02-springmvc分佈式項目dataService項目配置

spring總文件java

文件名:applicationContext.xmlnode

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:p="http://www.springframework.org/schema/p"
 6        xmlns:aop="http://www.springframework.org/schema/aop"
 7        xmlns:tx="http://www.springframework.org/schema/tx"
 8        xmlns:task="http://www.springframework.org/schema/task"
 9        xsi:schemaLocation="
10 http://www.springframework.org/schema/beans
11 http://www.springframework.org/schema/beans/spring-beans.xsd
12 http://www.springframework.org/schema/context
13 http://www.springframework.org/schema/context/spring-context.xsd
14 http://www.springframework.org/schema/tx
15 http://www.springframework.org/schema/tx/spring-tx.xsd
16 http://www.springframework.org/schema/aop
17 http://www.springframework.org/schema/aop/spring-aop.xsd">
18 
19     <!-- 加載系統配置文件 -->
20     <context:property-placeholder location="classpath:*.properties" />
21 
22     <!-- 掃描註解 -->
23     <context:component-scan base-package="com.bjpowernode.p2p.service" />
24 
25     <!-- 導入數據相關配置 -->
26     <import resource="applicationContext-datasource.xml" />
27     <!-- 導入 redis 配置 -->
28     <import resource="applicationContext-redis.xml" />
29     <!-- 導入服務提供者配置 -->
30     <import resource="applicationContext-dubbo-provider.xml"/>
31 </beans>

 

數據源配置文件mysql

文件名:applicationContext-datasource.xmlweb

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:context="http://www.springframework.org/schema/context"
 5        xmlns:p="http://www.springframework.org/schema/p"
 6        xmlns:aop="http://www.springframework.org/schema/aop"
 7        xmlns:tx="http://www.springframework.org/schema/tx"
 8        xmlns:task="http://www.springframework.org/schema/task"
 9        xsi:schemaLocation="
10 http://www.springframework.org/schema/beans
11 http://www.springframework.org/schema/beans/spring-beans.xsd
12 http://www.springframework.org/schema/context
13 http://www.springframework.org/schema/context/spring-context.xsd
14 http://www.springframework.org/schema/tx
15 http://www.springframework.org/schema/tx/spring-tx.xsd
16 http://www.springframework.org/schema/aop
17 http://www.springframework.org/schema/aop/spring-aop.xsd">
18 
19     <!-- 配置數據庫鏈接,阿里數據源 druid 鏈接池 -->
20     <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
21         <property name="url" value="jdbc:mysql://192.168.127.128:3306/p2p?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
22         <property name="username" value="root"/>
23         <property name="password" value="123456"/>
24     </bean>
25 
26     <!-- MyBatis sqlSessionFactory 配置 mybatis -->
27     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
28         <property name="configLocation" value="classpath:mybatis-configuration.xml"/>
29         <property name="dataSource" ref="dataSource"/>
30     </bean>
31     <!-- scan for mappers and let them be autowired -->
32     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
33         <property name="basePackage" value="com.bjpowernode.p2p.mapper"/>
34         <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
35     </bean>
36 
37     <!-- 事務相關控制 -->
38     <bean id="transactionManager"
39           class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
40         <property name="dataSource" ref="dataSource"/>
41     </bean>
42 
43     <tx:annotation-driven transaction-manager="transactionManager"/>
44 
45     <tx:advice id="txAdvice" transaction-manager="transactionManager">
46         <tx:attributes>
47             <!-- 對業務層全部方法添加事務,除了以 get、find、select 開始的 -->
48             <tx:method name="*" isolation="DEFAULT" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
49             <!-- 查詢操做沒有必要開啓事務,給只讀事務添加一個屬性 read-only -->
50             <tx:method name="get*" read-only="true"/>
51             <tx:method name="find*" read-only="true"/>
52             <tx:method name="select*" read-only="true"/>
53             <tx:method name="query*" read-only="true"/>
54         </tx:attributes>
55     </tx:advice>
56     <!-- Service 層事務控制 -->
57     <aop:config>
58         <aop:pointcut id="pointcut" expression="execution(* com.bjpowernode.p2p.service.**.*.*(..))"/>
59         <aop:advisor pointcut-ref="pointcut" advice-ref="txAdvice"/>
60     </aop:config>
61 </beans>

 

dubbo配置redis

文件名:applicationContext-dubbo-provider.xmlspring

<?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:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://code.alibabatech.com/schema/dubbo
        http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 服務提供者:應用名稱 -->
    <dubbo:application name="dataservice"/>

    <!-- 配置 zookeeper 註冊中心 -->
    <dubbo:registry protocol="zookeeper" address="192.168.127.128:2181"/>

    <!--產品業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.loan.LoanInfoService" ref="loanInfoServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>

    <!--用戶業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.loan.UserService" ref="userServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>

    <!--投資業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.loan.BidInfoService" ref="bidInfoServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>

    <!--賬戶業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.user.FinanceAccountService" ref="financeAccountServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>

    <!--redis業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.loan.RedisService" ref="redisServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>

    <!--收益業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.loan.IncomeRecordService" ref="incomeRecordServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>

    <!--充值業務-->
    <dubbo:service interface="com.bjpowernode.p2p.service.loan.RechargeRecordService" ref="rechargeRecordServiceImpl" version="1.0.0" timeout="15000"></dubbo:service>



</beans>

 

redis配置sql

文件名:applicationContext-redis.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:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- jedis Connection Factory -->
    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
          p:usePool="${redis.usePool}"
          p:hostName="${redis.hostName}"
          p:port="${redis.port}"
          p:timeout="${redis.timeout}"
          p:password="${redis.password}"/>


    <!-- redis template definition -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="jedisConnectionFactory"/>
    </bean>
</beans>

 

log4j配置express

文件名:log4j2.xmltomcat

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="debug">
    <appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <ThresholdFilter level="debug" onMatch="ACCEPT"
                             onMismatch="ACCEPT"/>
            <PatternLayout pattern="[dataservice] %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
        </Console>
        <RollingFile name="RollingFile"
                     fileName="/opt/tomcat_dataservice/logs/dataservice.log"
                     filePattern="/opt/tomcat_dataservice/logs/$${date:yyyy-MM}/dataservice-%d{MM-dd-yyyy}-%i.log.gz">
            <PatternLayout
                    pattern="[dataservice] %d{yyyy-MM-dd 'at' HH:mm:ss z} %-5level %class{36} %L %M - %msg%xEx%n"/>
            <SizeBasedTriggeringPolicy size="100MB"/>
        </RollingFile>
    </appenders>
    <loggers>
        <logger name="com.bjpowernode.p2p.mapper"
                level="debug"/>
        <root level="debug">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFile"/>
        </root>
    </loggers>
</configuration>

 

mybatis配置

文件名:mybatis-configuration.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>
    <!-- log4j2 與 mybatis 集成,目的是打印出 sql 語句 -->
    <settings>
        <setting name="logImpl" value="LOG4J2"/>
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
</configuration>

 

redis屬性配置

文件名:redis.properties

#redis config
redis.usePool=true
redis.hostName=192.168.127.128
redis.port=6379
redis.timeout=8000
redis.password=123456

 

web.xml的配置

文件名:web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="dataservice" version="3.0">
    <display-name>dataservice application</display-name>
    <!-- spring 監聽器加載 applicationContext.xml 配置文件 -->
    <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>
    <!-- spring 字符過濾器 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
相關文章
相關標籤/搜索