<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-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/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
">
<!-- 扫描包中的类 -->
<context:component-scan base-package="com.etc.service" />
<context:component-scan base-package="com.etc.filter" />
<mvc:annotation-driven/>
<!-- 加载数据库连接信息的属性文件 jdbc.properties -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config/jdbc.properties" />
</bean>
<!-- 配置数据源,数据源提供了与数据库连接的技术及连接池技术 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://172.16.21.100:3306/blog_backups?characterEncoding=utf-8" />
<property name="username" value="blog" />
<property name="password" value="blog" />
<property name="initialSize" value="5" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="10" />
<property name="minIdle" value="5" />
<property name="maxWait" value="1200" />
</bean>
<!-- 配置mybatis的sqlSessionFactory -->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置数据库连接池 -->
<property name="dataSource" ref="dataSource"/>
<!-- 加载mybatis配置文件 -->
<property name="configLocation" value="classpath:config/mybatis-config.xml"/>
<!-- 自动扫描dao下的Xx.xml文件 -->
<property name="mapperLocations" value="classpath:com/etc/dao/*.xml"/>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- dao接口所在包名,Spring会自动查找其下的类并注入到Spring的容器中 -->
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean"/>
<property name="basePackage" value="com.etc.dao"/>
</bean>
<!-- 声明事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 绑定数据源 -->
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 启动事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
applicationcontext.xml
最新推荐文章于 2024-06-29 11:37:30 发布