标签:policy autowire redis配置 one ase span mis execution connect
spring总文件
文件名:applicationContext.xml
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>
数据源配置文件
文件名:applicationContext-datasource.xml
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&useUnicode=true&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配置
文件名:applicationContext-dubbo-provider.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: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配置
文件名: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配置
文件名:log4j2.xml
<?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>
02-springmvc分布式项目dataService项目配置
标签:policy autowire redis配置 one ase span mis execution connect
原文地址:https://www.cnblogs.com/Tpf386/p/10982255.html