A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 我是楠楠 于 2019-10-23 14:56 编辑

【郑州校区】传智健康项目讲义第一章之环境搭建 四

创建health_service_provider,子工程,打包方式为war,作为服务单独部署,存放服务类、Dao接口和Mapper映射文件等
pom.xml

[AppleScript] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF‐8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
[url=http://maven.apache.org/xsd/maven]http://maven.apache.org/xsd/maven[/url]‐4.0.0.xsd">
<parent>
<groupId>com.itheima</groupId>
<artifactId>health_parent</artifactId>
<version>1.0‐SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>health_service_provider</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.itheima</groupId>
<artifactId>health_interface</artifactId>
<version>1.0‐SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7‐maven‐plugin</artifactId>
<configuration>
<!‐‐ 指定端口 ‐‐>
<port>81</port>
<!‐‐ 请求路径 ‐‐>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>

log4j.properties

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.err
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L
‐ %m%n
### direct messages to file mylog.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=c:\\mylog.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L ‐
%m%n
### set log levels ‐ for more verbose logging change 'info' to 'debug'
###
log4j.rootLogger=debug, stdout

SqlMapConfig.xml
[AppleScript] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF‐8" ?>
<!DOCTYPE configuration PUBLIC "‐//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis‐3‐config.dtd">
<configuration>
<plugins>
<!‐‐ com.github.pagehelper 为 PageHelper 类所在包名 ‐‐>
<plugin interceptor="com.github.pagehelper.PageHelper">
<!‐‐ 设置数据库类型
Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL 六种数据库‐‐>
<property name="dialect" value="mysql"/>
</plugin>
</plugins>
</configuration> 


spring-dao.xml

[AppleScript] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF‐8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url=http://www.springframework.org/schema/beans/spring]http://www.springframework.org/schema/beans/spring[/url]‐beans‐4.2.xsd
[url=http://www.springframework.org/schema/context]http://www.springframework.org/schema/context[/url]
[url=http://www.springframework.org/schema/context/spring]http://www.springframework.org/schema/context/spring[/url]‐context.xsd
[url=http://www.springframework.org/schema/aop]http://www.springframework.org/schema/aop[/url]
[url=http://www.springframework.org/schema/aop/spring]http://www.springframework.org/schema/aop/spring[/url]‐aop.xsd
[url=http://www.springframework.org/schema/tx]http://www.springframework.org/schema/tx[/url]
[url=http://www.springframework.org/schema/tx/spring]http://www.springframework.org/schema/tx/spring[/url]‐tx.xsd
[url=http://www.springframework.org/schema/util]http://www.springframework.org/schema/util[/url]
[url=http://www.springframework.org/schema/util/spring]http://www.springframework.org/schema/util/spring[/url]‐util.xsd">
<!‐‐数据源‐‐>
<bean id="dataSource"
class="com.alibaba.druid.pool.DruidDataSource" destroy‐
method="close">
<property name="username" value="root" />
<property name="password" value="root" />
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/health"
/>
</bean>
<!‐‐spring和mybatis整合的工厂bean‐‐>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation"
value="classpath:SqlMapConfig.xml" />
</bean>
<!‐‐批量扫描接口生成代理对象‐‐>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!‐‐指定接口所在的包‐‐>
<property name="basePackage" value="com.itheima.dao" />
</bean>
</beans> 

spring-tx.xml

[AppleScript] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF‐8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url=http://www.springframework.org/schema/beans/spring]http://www.springframework.org/schema/beans/spring[/url]‐beans.xsd
[url=http://www.springframework.org/schema/mvc]http://www.springframework.org/schema/mvc[/url]
[url=http://www.springframework.org/schema/mvc/spring]http://www.springframework.org/schema/mvc/spring[/url]‐
mvc.xsd
[url=http://www.springframework.org/schema/tx]http://www.springframework.org/schema/tx[/url]
[url=http://www.springframework.org/schema/tx/spring]http://www.springframework.org/schema/tx/spring[/url]‐
tx.xsd
[url=http://www.springframework.org/schema/context]http://www.springframework.org/schema/context[/url]
[url=http://www.springframework.org/schema/context/spring]http://www.springframework.org/schema/context/spring[/url]‐context.xsd">
<!‐‐ 事务管理器 ‐‐>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!‐‐
开启事务控制的注解支持
注意:此处必须加入proxy‐target‐class="true",
需要进行事务控制,会由Spring框架产生代理对象,
Dubbo需要将Service发布为服务,要求必须使用cglib创建代理对象。
‐‐>
<tx:annotation‐driven transaction‐manager="transactionManager"
proxy‐target‐class="true"/>
</beans> 

spring-service.xml

[AppleScript] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF‐8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema‐instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
[url=http://www.springframework.org/schema/beans/spring]http://www.springframework.org/schema/beans/spring[/url]‐beans.xsd
[url=http://www.springframework.org/schema/mvc]http://www.springframework.org/schema/mvc[/url]
[url=http://www.springframework.org/schema/mvc/spring]http://www.springframework.org/schema/mvc/spring[/url]‐mvc.xsd
[url=http://code.alibabatech.com/schema/dubbo]http://code.alibabatech.com/schema/dubbo[/url]
[url=http://code.alibabatech.com/schema/dubbo/dubbo.xsd]http://code.alibabatech.com/schema/dubbo/dubbo.xsd[/url]
[url=http://www.springframework.org/schema/context]http://www.springframework.org/schema/context[/url]
[url=http://www.springframework.org/schema/context/spring]http://www.springframework.org/schema/context/spring[/url]‐context.xsd">
<!‐‐ 指定应用名称 ‐‐>
<dubbo:application name="health_service_provider"/>
<!‐‐指定暴露服务的端口,如果不指定默认为20880‐‐>
<dubbo:protocol name="dubbo" port="20887"/>
<!‐‐指定服务注册中心地址‐‐>
<dubbo:registry address="zookeeper://127.0.0.1:2181"/>
<!‐‐批量扫描,发布服务‐‐>
<dubbo:annotation package="com.itheima.service"/>
</beans> 

web.xml

[AppleScript] 纯文本查看 复制代码
<!DOCTYPE web‐app PUBLIC
"‐//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web‐app_2_3.dtd" >
<web‐app>
<display‐name>Archetype Created Web Application</display‐name>
<!‐‐ 加载spring容器 ‐‐>
<context‐param>
<param‐name>contextConfigLocation</param‐name>
<param‐value>classpath*:applicationContext*.xml</param‐value>
</context‐param>
<listener>
<listener‐
class>org.springframework.web.context.ContextLoaderListener</listener‐
class>
</listener>
</web‐app> 


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马