<?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"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 自动扫描注解的bean 多个包以 逗号分隔-->
<context:component-scan base-package="com.sun" />
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 引入jdbc配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="locations">
<list>
<value>classpath:properties/*.properties</value>
<!--要是有多个配置文件,只需在这里继续添加即可 -->
</list>
</property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 不使用properties来配置 -->
<!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/learning" />
<property name="username" value="root" />
<property name="password" value="christmas258@" /> -->
<!-- 使用properties来配置 -->
<property name="driverClassName" value="${jdbc_driverClassName}" />
<property name="url" value="${jdbc_url}"/>
<property name="username" value="${jdbc_username}"/>
<property name="password" value="${jdbc_password}"/>
</bean>
<!-- mapper接口代理实现,自动扫描了所有的XxxxMapper.xml对应的mapper接口文件,这样就不用一个一个手动配置Mpper的映射了,只要Mapper接口类和Mapper映射文件对应起来就可以了。 -->
<!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >-->
<!--<!–指定扫描整个包,多个包用英文","分隔符–>-->
<!--<property name="basePackage" value="com.sun.dao" />-->
<!--</bean>-->
<!-- 配置Mybatis的文件 ,mapperLocations配置**Mapper.xml文件位置,configLocation配置mybatis-config文件位置-->
<!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:orm.mybatis/*.xml"/>
<!–<property name="configLocation" value="classpath:config/mybatis-config.xml" />–>
<!– <property name="typeAliasesPackage" value="com.tiantian.ckeditor.model"
/> –>
</bean>-->
<!--配置hibernate文件,hibernateProperties是-->
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!--注入连接池-->
<property name="dataSource" ref="dataSource"/>
<!--hibernate常用配置-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!--hibernate 映射文件配置-->
<!--<property name="mappingLocations">
<list>
<value>classpath:orm/hibernate/hibernate.hbm.xml</value>
</list>
</property>-->
<!--hibernate 映射包配置-->
<!--<property name="mappingDirectoryLocations">
<list>
<value>classpath:orm/hibernate/</value>
</list> </property>-->
<!--hibernate 自动扫描注解包配置-->
<!--<property name="packagesToScan">
<list>
<value>classpath:com.sun.dto.po</value>
</list>
</property>-->
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="txManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--开启事务注解扫描-->
<tx:annotation-driven transaction-manager="txManage"/>
</beans>
<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"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 自动扫描注解的bean 多个包以 逗号分隔-->
<context:component-scan base-package="com.sun" />
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!-- 引入jdbc配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
<property name="locations">
<list>
<value>classpath:properties/*.properties</value>
<!--要是有多个配置文件,只需在这里继续添加即可 -->
</list>
</property>
</bean>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 不使用properties来配置 -->
<!-- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/learning" />
<property name="username" value="root" />
<property name="password" value="christmas258@" /> -->
<!-- 使用properties来配置 -->
<property name="driverClassName" value="${jdbc_driverClassName}" />
<property name="url" value="${jdbc_url}"/>
<property name="username" value="${jdbc_username}"/>
<property name="password" value="${jdbc_password}"/>
</bean>
<!-- mapper接口代理实现,自动扫描了所有的XxxxMapper.xml对应的mapper接口文件,这样就不用一个一个手动配置Mpper的映射了,只要Mapper接口类和Mapper映射文件对应起来就可以了。 -->
<!--<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" >-->
<!--<!–指定扫描整个包,多个包用英文","分隔符–>-->
<!--<property name="basePackage" value="com.sun.dao" />-->
<!--</bean>-->
<!-- 配置Mybatis的文件 ,mapperLocations配置**Mapper.xml文件位置,configLocation配置mybatis-config文件位置-->
<!-- <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:orm.mybatis/*.xml"/>
<!–<property name="configLocation" value="classpath:config/mybatis-config.xml" />–>
<!– <property name="typeAliasesPackage" value="com.tiantian.ckeditor.model"
/> –>
</bean>-->
<!--配置hibernate文件,hibernateProperties是-->
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!--注入连接池-->
<property name="dataSource" ref="dataSource"/>
<!--hibernate常用配置-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!--hibernate 映射文件配置-->
<!--<property name="mappingLocations">
<list>
<value>classpath:orm/hibernate/hibernate.hbm.xml</value>
</list>
</property>-->
<!--hibernate 映射包配置-->
<!--<property name="mappingDirectoryLocations">
<list>
<value>classpath:orm/hibernate/</value>
</list> </property>-->
<!--hibernate 自动扫描注解包配置-->
<!--<property name="packagesToScan">
<list>
<value>classpath:com.sun.dto.po</value>
</list>
</property>-->
</bean>
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="txManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--开启事务注解扫描-->
<tx:annotation-driven transaction-manager="txManage"/>
</beans>