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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 谷粒姐姐 于 2019-10-9 10:54 编辑

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

pom.xml:
[XML] 纯文本查看 复制代码
<?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     
                       'http://maven.apache.org/xsd/maven‐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:
[Plain Text] 纯文本查看 复制代码
 
### 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:
[XML] 纯文本查看 复制代码
<?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:
[XML] 纯文本查看 复制代码
<?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
                            'http://www.springframework.org/schema/beans/spring‐beans‐4.2.xsd'
                            'http://www.springframework.org/schema/context'
                            'http://www.springframework.org/schema/context/spring‐context.xsd'
                            'http://www.springframework.org/schema/aop'
                            'http://www.springframework.org/schema/aop/spring‐aop.xsd'
                            'http://www.springframework.org/schema/tx'
                            'http://www.springframework.org/schema/tx/spring‐tx.xsd'
                            'http://www.springframework.org/schema/util'
                            'http://www.springframework.org/schema/util/spring‐util.xsd'">
    <!‐‐数据源‐‐>
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroymethod="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:
[XML] 纯文本查看 复制代码
<?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
                       
'http://www.springframework.org/schema/beans/spring‐beans.xsd'                    
     'http://www.springframework.org/schema/mvc'                  
       'http://www.springframework.org/schema/mvc/springmvc.xsd'
                        'http://www.springframework.org/schema/tx'                  
       'http://www.springframework.org/schema/tx/springtx.xsd'
                        'http://www.springframework.org/schema/context'
                        'http://www.springframework.org/schema/context/spring‐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:
[XML] 纯文本查看 复制代码
<?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
                            
'http://www.springframework.org/schema/beans/spring‐beans.xsd'         
                'http://www.springframework.org/schema/mvc'
'http://www.springframework.org/schema/mvc/spring‐mvc.xsd'
                            'http://code.alibabatech.com/schema/dubbo'
                            'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'
                            'http://www.springframework.org/schema/context'
                            'http://www.springframework.org/schema/context/spring‐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:
[XML] 纯文本查看 复制代码
<!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>
        <listenerclass>org.springframework.web.context.ContextLoaderListener</listenerclass>
    </listener>
</web‐app>


0 个回复

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