<!-- 资源文件配置 --><beans profile="dev"><bean class="com.ningpai.util.CustomPropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/com/ningpai/web/config/dev/jdbc.properties</value><value>classpath:/com/ningpai/web/config/dev/es-hosts.properties</value><value>classpath:/com/ningpai/web/config/dev/redis.properties</value><value>classpath:/com/ningpai/web/config/dev/amq.properties</value><value>classpath:/com/ningpai/web/config/dev/config.properties</value><value>classpath:/com/ningpai/web/config/dev/kaQuan.properties</value><value>classpath:/com/ningpai/web/config/dev/zjlogin.properties</value><value>classpath:/com/ningpai/web/config/dev/kuaidi100.properties</value><value>classpath:/com/ningpai/web/config/dev/resource.properties</value><value>classpath:/com/ningpai/web/config/dev/czb.properties</value><value>classpath:/com/ningpai/web/config/dev/hzb.properties</value><value>classpath:/com/ningpai/web/config/dev/jlPay.properties</value></list></property></bean></beans>
package com.ningpai.util;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import java.util.HashMap;
import java.util.Map;
import java.util.Properties;/*** Created by Intellij Idea** @auth hangzhou.team.rmitec* @company shanghai ruimin internet technology co.ltd* @date 2017/12/12*/
public class CustomPropertyPlaceholderConfigurer extends org.springframework.beans.factory.config.PropertyPlaceholderConfigurer {private static Map<String, String> ctxPropertiesMap = new HashMap<String, String>();@Overrideprotected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,Properties props) throws BeansException {super.processProperties(beanFactoryToProcess, props);for (Object key : props.keySet()) {String keyStr = key.toString();String value = props.getProperty(keyStr);ctxPropertiesMap.put(keyStr, value);}}/*** 读取配置** @param name* @return*/public static String getProperty(String name) {return ctxPropertiesMap.get(name);}
}
完整的application.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:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:task="http://www.springframework.org/schema/task"xmlns:redisson="http://redisson.org/schema/redisson"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsdhttp://redisson.org/schema/redissonhttp://redisson.org/schema/redisson/redisson.xsd"><import resource="spring-jcaptcha.xml" /><import resource="spring-plugin.xml" /><!--创建一个Spring Bean的名称springSessionRepositoryFilter实现过滤器。
筛选器负责将HttpSession实现替换为Spring会话支持。在这个实例中,Spring会话得到了Redis的支持。--><bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration"><property name="maxInactiveIntervalInSeconds" value="604800"/></bean><bean class="org.springframework.session.web.http.DefaultCookieSerializer"><property name="cookieName" value="JSESSIONID"/></bean><!--创建了一个RedisConnectionFactory,它将Spring会话连接到Redis服务器。我们配置连接到默认端口(6379)上的本地主机!-->
<!-- <bean class="org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"/>--><!--<osgi:reference id="dataSource" interface="javax.sql.DataSource" bean-name="dataSource"/>--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"init-method="init" destroy-method="close"><property name="driverClassName" value="${jdbc.driver}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><!-- data source configuration --><property name="initialSize" value="50" /><!-- initial connections --><property name="maxActive" value="200" /><!-- MAX connections --><property name="maxIdle" value="50" /><!-- MAX idle connections --><property name="minIdle" value="10" /><!-- MIN idle connections --><!-- 处理mysql 8小时自动断开连接的问题 --><property name="testWhileIdle" value="true" /><property name="testOnBorrow" value="true" /><property name="testOnReturn" value="false" /><property name="validationQuery" value="select 1" /><property name="validationQueryTimeout" value="15" /><property name="connectionInitSqls" value="set names utf8mb4;"/><property name="timeBetweenEvictionRunsMillis" value="20000" /><property name="numTestsPerEvictionRun" value="100" /><!--属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:监控统计用的filter:stat日志用的filter:log4j防御SQL注入的filter:wall --><property name="filters" value="${druid.filters}" /></bean><!--事务相关控制--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource" /></bean><!-- 事务传播特性 --><bean id="txDefinitionNew" class="org.springframework.transaction.support.DefaultTransactionDefinition"><property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW" /><property name="isolationLevel" value="2"></property></bean><context:component-scan base-package="com.ningpai,com.qianmi,com.zjfae"/><!--启动注解 @Transactional --><tx:annotation-driven/><!--<tx:advice id="userTxAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception"/></tx:attributes></tx:advice><aop:config><aop:pointcut id="pc" expression="execution(* com.ningpai.web.impl.*.*(..)) " />把事务控制在Business层<aop:advisor pointcut-ref="pc" advice-ref="userTxAdvice" /></aop:config>--><!-- MyBatis sqlSessionFactory 配置 mybatis--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="configLocation"value="classpath:/com/ningpai/web/mybatis/SqlMapConfig.xml" /><property name="dataSource" ref="dataSource" /><property name="mapperLocations"><array><value>classpath*:com/qianmi/*/mapper/**/*.xml</value><value>classpath*:com/ningpai/mybatis/mapper/DepositInfoMapper.xml</value><value>classpath*:com/ningpai/mybatis/mapper/TradeInfoMapper.xml</value></array></property></bean><bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"><constructor-arg index="0" ref="sqlSessionFactory" /></bean><!-- 设置字段内容长度,这里不做限定 --><bean id="mappingJacksonHttpMessageConverter"class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" /><!--esClientManager,设置为单例--><bean id="esClientManager" class="com.ningpai.searchplatform.client.ESClientManager" scope="singleton"><constructor-arg index="0" type="java.lang.String"><value>${es.hosts}</value></constructor-arg><constructor-arg index="1" type="java.lang.String" value="${es.cluster.name}"/></bean><!-- 线程池 --><!--spring线程池--><bean id="threadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"><!--核心线程数--><property name="corePoolSize" value="20"/><!--最大线程数--><property name="maxPoolSize" value="50"/><!--队列最大长度--><property name="queueCapacity" value="200"/><!--线程池维护线程所允许的空闲时间--><property name="keepAliveSeconds" value="300"/><!--程序关闭时等待线程执行完毕--><property name="waitForTasksToCompleteOnShutdown" value="true"/></bean><task:scheduled-tasks><task:scheduled ref="RefundmentUtil" method="service" cron="0 0 12 * * ?" /></task:scheduled-tasks><bean id="redisAdapter" class="com.ningpai.redis.RedisAdapter" scope="singleton"></bean><bean id="redisProductCache" class="com.zjfae.goods.redis.RedisProductCache" scope="singleton"></bean><bean id="redisMarketingCache" class="com.qianmi.marketing.redis.RedisMarketingCache" scope="singleton"></bean><bean id="redisTopicCache" class="com.zjfae.topic.redis.RedisTopicCache" scope="singleton"></bean><bean id="SpringApplicationContext" class="com.ningpai.common.util.ApplicationContextHelper"></bean><bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"><property name="maxIdle" value="${redis.maxIdle}" /><property name="maxTotal" value="${redis.maxActive}" /><property name="maxWaitMillis" value="${redis.maxWait}" /><property name="testOnBorrow" value="${redis.testOnBorrow}" /></bean><bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"p:host-name="${redis.host}" p:port="${redis.port}" p:database="${redis.dbIndex}" p:pool-config-ref="poolConfig"/><bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate"><property name="connectionFactory" ref="connectionFactory" /></bean><!--redission 相关配置 请勿改动 --><redisson:client id="redissonClient"><redisson:single-server address="redis://${redis.host}:${redis.port}" /></redisson:client><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"></property></bean><!--wxClientCredential--><bean id="wxClientCredential" class="com.ningpai.m.weixin.util.WxClientCredential" scope="singleton" /><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.ningpai.deposit.mapper,com.qianmi.marketing.dao,com.ningpai.marketing.dao.point,com.qianmi.coupon.mapper,com.qianmi.couponGroup.dao,com.qianmi.couponRedeem.dao,com.qianmi.newCustomerConfig.dao,com.qianmi.receive.dao,com.qianmi.promotioner.dao,com.ningpai.report.dao,com.ningpai.dict.dao,com.ningpai.commentResources.dao,com.ningpai.customer.dao.balance,com.ningpai.customer.dao.channelCustomerInfo,com.ningpai.customermerge.dao,com.ningpai.customerOption.dao,com.ningpai.privacyAgreement.dao,com.ningpai.system.dao.weixin,com.ningpai.system.dao.channelSet,com.ningpai.system.dao.outlet,com.ningpai.system.dao.common,com.zjfae.goods.dao,com.qianmi.site.common.dao,com.qianmi.marketing.groupon.dao,com.qianmi.invoice.dao,com.zjfae.flow.dao,com.zjfae.common.dao,com.zjfae.strategy.dao,com.zjfae.hop.dao,com.zjfae.jushuitan.dao,com.zjfae.nuonuo.dao,com.zjfae.report.dao,com.zjfae.share.dao,com.zjfae.goods.dao,com.zjfae.topic.dao,com.zjfae.order.daocom.ningpai.system.trans.dao,com.zjfae.white.dao,com.zjfae.vending.dao,com.ningpai.goods.dao.unexpress,com.ningpai.customer.dao.zjfae,com.ningpai.customer.dao.shareApply,com.zjfae.pay.dao,com.zjfae.page.dao,com.zjfae.domain.dao,com.zjfae.wxlogistics.dao,com.zjfae.log.dao,com.ningpai.goods.dao.erp,com.ningpai.marketing.dao.receiveRecord"/></bean><import resource="classpath*:spring-amq.xml"/><import resource="classpath*:spring-promotioner.xml"/><!-- 资源文件配置 --><beans profile="dev"><bean class="com.ningpai.util.CustomPropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/com/ningpai/web/config/dev/jdbc.properties</value><value>classpath:/com/ningpai/web/config/dev/es-hosts.properties</value><value>classpath:/com/ningpai/web/config/dev/redis.properties</value><value>classpath:/com/ningpai/web/config/dev/amq.properties</value><value>classpath:/com/ningpai/web/config/dev/config.properties</value><value>classpath:/com/ningpai/web/config/dev/kaQuan.properties</value><value>classpath:/com/ningpai/web/config/dev/zjlogin.properties</value><value>classpath:/com/ningpai/web/config/dev/kuaidi100.properties</value><value>classpath:/com/ningpai/web/config/dev/resource.properties</value><value>classpath:/com/ningpai/web/config/dev/czb.properties</value><value>classpath:/com/ningpai/web/config/dev/hzb.properties</value><value>classpath:/com/ningpai/web/config/dev/jlPay.properties</value></list></property></bean></beans><beans profile="test"><bean class="com.ningpai.util.CustomPropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/com/ningpai/web/config/test/jdbc.properties</value><value>classpath:/com/ningpai/web/config/test/es-hosts.properties</value><value>classpath:/com/ningpai/web/config/test/redis.properties</value><value>classpath:/com/ningpai/web/config/test/amq.properties</value><value>classpath:/com/ningpai/web/config/test/config.properties</value><value>classpath:/com/ningpai/web/config/test/kaQuan.properties</value><value>classpath:/com/ningpai/web/config/test/zjlogin.properties</value><value>classpath:/com/ningpai/web/config/test/kuaidi100.properties</value><value>classpath:/com/ningpai/web/config/test/resource.properties</value><value>classpath:/com/ningpai/web/config/test/czb.properties</value><value>classpath:/com/ningpai/web/config/test/hzb.properties</value><value>classpath:/com/ningpai/web/config/test/jlPay.properties</value></list></property></bean></beans><beans profile="uat"><bean class="com.ningpai.util.CustomPropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/com/ningpai/web/config/uat/jdbc.properties</value><value>classpath:/com/ningpai/web/config/uat/es-hosts.properties</value><value>classpath:/com/ningpai/web/config/uat/redis.properties</value><value>classpath:/com/ningpai/web/config/uat/amq.properties</value><value>classpath:/com/ningpai/web/config/uat/config.properties</value><value>classpath:/com/ningpai/web/config/uat/kaQuan.properties</value><value>classpath:/com/ningpai/web/config/uat/zjlogin.properties</value><value>classpath:/com/ningpai/web/config/uat/kuaidi100.properties</value><value>classpath:/com/ningpai/web/config/uat/resource.properties</value><value>classpath:/com/ningpai/web/config/uat/czb.properties</value><value>classpath:/com/ningpai/web/config/uat/hzb.properties</value><value>classpath:/com/ningpai/web/config/uat/jlPay.properties</value></list></property></bean></beans><beans profile="prd"><bean class="com.ningpai.util.CustomPropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/com/ningpai/web/config/prd/jdbc.properties</value><value>classpath:/com/ningpai/web/config/prd/es-hosts.properties</value><value>classpath:/com/ningpai/web/config/prd/redis.properties</value><value>classpath:/com/ningpai/web/config/prd/amq.properties</value><value>classpath:/com/ningpai/web/config/prd/config.properties</value><value>classpath:/com/ningpai/web/config/prd/kaQuan.properties</value><value>classpath:/com/ningpai/web/config/prd/zjlogin.properties</value><value>classpath:/com/ningpai/web/config/prd/kuaidi100.properties</value><value>classpath:/com/ningpai/web/config/prd/resource.properties</value><value>classpath:/com/ningpai/web/config/prd/czb.properties</value><value>classpath:/com/ningpai/web/config/prd/hzb.properties</value><value>classpath:/com/ningpai/web/config/prd/jlPay.properties</value></list></property></bean></beans>
</beans>