<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- database 连接配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<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>
<context:property-placeholder location="conf/jdbc/jdbc.properties" />
<!-- 配置Hibernate 因用的spring4.1.6版本所以 这里需hibernate4版本 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 在spring中加载hibernate.cfg.xml配置 -->
<property name="configLocation" value="classpath:conf/hibernate/hibernate.cfg.xml" />
<!-- <property name="mappingResources"> <value>conf/model/student.hbm.xml</value>
</property> 这里是spring中加载hibernate实体配置文件,因考虑项目分工,个人建议还是将实体映射交给hibernate处理-->
</bean>
<!-- AOP切面进去,告诉方法用transation -->
<aop:config>
<aop:pointcut expression="execution(* org.ssh.service.*.*(..))" id="servicePointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"/>
</aop:config>
<!-- spring事务管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- 一下内容为凡是方法名以get、query、find开头的都是readonly,其他军事默认是REQUIRED -->
<tx:method name="get*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"/>
<!-- 在spring中默认就是required -->
</tx:attributes>
</tx:advice>
<import resource="student_spring.xml" />
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.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/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- database 连接配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<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>
<context:property-placeholder location="conf/jdbc/jdbc.properties" />
<!-- 配置Hibernate 因用的spring4.1.6版本所以 这里需hibernate4版本 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 在spring中加载hibernate.cfg.xml配置 -->
<property name="configLocation" value="classpath:conf/hibernate/hibernate.cfg.xml" />
<!-- <property name="mappingResources"> <value>conf/model/student.hbm.xml</value>
</property> 这里是spring中加载hibernate实体配置文件,因考虑项目分工,个人建议还是将实体映射交给hibernate处理-->
</bean>
<!-- AOP切面进去,告诉方法用transation -->
<aop:config>
<aop:pointcut expression="execution(* org.ssh.service.*.*(..))" id="servicePointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut"/>
</aop:config>
<!-- spring事务管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- 一下内容为凡是方法名以get、query、find开头的都是readonly,其他军事默认是REQUIRED -->
<tx:method name="get*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="add*" propagation="REQUIRED"/>
<!-- 在spring中默认就是required -->
</tx:attributes>
</tx:advice>
<import resource="student_spring.xml" />
</beans>