完整配置
- 配置了redis,AOP,mysql,mybatis
<?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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
<!-- 开启懒加载-->
default-lazy-init="true">
<description>Spring公共配置 </description>
<context:component-scan base-package="org.ecinsight">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="org.ecinsight.entity" />
<property name="mapperLocations" value="classpath:/mybatis/*.xml" />
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.ecinsight.dao" />
<property name="annotationClass" value="org.ecinsight.dao.MyBatisRepository" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="NESTED"
rollback-for="Exception" />
<tx:method name="add*" propagation="NESTED" rollback-for="Exception" />
<tx:method name="update*" propagation="NESTED"
rollback-for="Exception" />
<tx:method name="modify*" propagation="NESTED"
rollback-for="Exception" />
<tx:method name="edit*" propagation="NESTED" rollback-for="Exception" />
<tx:method name="del*" propagation="NESTED" rollback-for="Exception" />
<tx:method name="bind*" propagation="NESTED" rollback-for="Exception" />
<tx:method name="save*" propagation="NESTED" rollback-for="Exception" />
<tx:method name="send*" propagation="NESTED" rollback-for="Exception" />
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="search*" read-only="true" />
<tx:method name="select*" read-only="true" />
<tx:method name="count*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="service"
expression="execution(* org.ecinsight.service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="service"
order="1" />
</aop:config>
<bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
</bean>
<bean id ="taskExecutor" class ="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >
<property name ="corePoolSize" value ="5" />
<property name ="maxPoolSize" value ="200" />
<property name ="queueCapacity" value ="200" />
</bean>
<bean id="stringSerializer"
class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
<property name="keySerializer" ref="stringSerializer" />
</bean>
<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory" />
</bean>
<beans profile="production">
<context:property-placeholder ignore-unresolvable="true"
location="classpath*:/application.properties" />
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}" />
<property name="filters" value="stat"></property>
<property name="maxActive" value="${jdbc.pool.maxActive}"></property>
<property name="initialSize" value="${jdbc.pool.initialSize}"></property>
<property name="maxWait" value="${jdbc.pool.maxWait}"></property>
<property name="minIdle" value="${jdbc.pool.minIdle}"></property>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.pool.timeBetweenEvictionRunsMillis}"></property>
<property name="minEvictableIdleTimeMillis" value="${jdbc.pool.minEvictableIdleTimeMillis}"></property>
<property name="validationQuery" value="SELECT 'x'"></property>
<property name="testWhileIdle" value="${jdbc.pool.testWhileIdle}"></property>
<property name="testOnBorrow" value="${jdbc.pool.testOnBorrow}"></property>
<property name="testOnReturn" value="${jdbc.pool.testOnReturn}"></property>
<property name="poolPreparedStatements" value="${jdbc.pool.poolPreparedStatements}"></property>
<property name="maxOpenPreparedStatements" value="${jdbc.pool.maxOpenPreparedStatements}"></property>
</bean>
<bean id="redisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.hostName}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.password}" />
<property name="poolConfig" ref="redisPoolConfig" />
</bean>
</beans>
</beans>