首页 > 代码库 > spring 配置 applicationContext.xml
spring 配置 applicationContext.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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<!-- 自动扫描 -->
<context:component-scan base-package="com.exayong">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 配置使Spring采用CGLIB代理 -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 启用对事务注解的支持 -->
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true" />
<!-- 对dataSource 数据源进行事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<!-- dataSource 配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<!-- 基本属性 url、user、password -->
<property name="url" value="http://www.mamicode.com/jdbc:mysql://localhost:3306/arc1?useUnicode=true&characterEncoding=UTF-8" />
<property name="username" value="http://www.mamicode.com/root" />
<property name="password" value="" />
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="http://www.mamicode.com/1" />
<property name="minIdle" value="http://www.mamicode.com/1" />
<property name="maxActive" value="http://www.mamicode.com/20" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="http://www.mamicode.com/60000" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="http://www.mamicode.com/60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="http://www.mamicode.com/300000" />
<property name="validationQuery" value="http://www.mamicode.com/SELECT ‘x‘" />
<property name="testWhileIdle" value="http://www.mamicode.com/true" />
<property name="testOnBorrow" value="http://www.mamicode.com/false" />
<property name="testOnReturn" value="http://www.mamicode.com/false" />
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="http://www.mamicode.com/false" />
<property name="maxPoolPreparedStatementPerConnectionSize"
value="http://www.mamicode.com/20" />
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="http://www.mamicode.com/stat" />
</bean>
<!-- mybatis文件配置,扫描所有mapper文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml"
p:mapperLocations="classpath:com/exayong/**/*Mapper.xml" />
<!-- spring与mybatis整合配置,扫描所有dao 自动实现 有 @Repository 的才会扫-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:basePackage="com.exayong"
p:annotationClass="org.springframework.stereotype.Repository"
/>
</beans>
spring 配置 applicationContext.xml