<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/ssh2</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123456</value>
</property>
</bean>
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/zhanghaobo/bean/User.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 哪些类哪些方法使用事务 -->
<aop:config>
<!-- 定义在哪些方法上开启事务-->
<aop:pointcut expression="execution(* com.zhanghaobo.service.impl.*.*(..))" id="allManagerMethod"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
<aop:aspect id="authorAspect" ref="authorityInterceptor">
<aop:before method="checkAuthor" pointcut-ref="allManagerMethod"/>
</aop:aspect>
</aop:config>
<!-- 事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<bean id="authorityInterceptor" class="com.zhanghaobo.interceptor.AuthorityInterceptor">
<property name="user">
<value>aaa</value>
</property>
</bean>
<bean id="userService" class="org.springframework.aop.framework.ProxyFactoryBean" >
<property name="target" ref="userServiceTarget"></property>
<property name="proxyInterfaces">
<value>com.zhanghaobo.service.UserService</value>
</property> <property name="interceptorNames">
<value>authorityInterceptor</value>
</property>
</bean>
<bean id="userDao" class="com.zhanghaobo.dao.impl.UserDAOImpl" scope="singleton">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userServiceTarget" class="com.zhanghaobo.service.impl.UserServiceImpl" scope="singleton">
<property name="userdao" ref="userDao"></property>
</bean>
<bean id="saveUserAction" class="com.zhanghaobo.action.user.SaveUserAction" scope="prototype">
<property name="userService" ref="userService"></property>
</bean>
<bean id="listUserAction" class="com.zhanghaobo.action.user.listUser" >
<property name="userService" ref="userService"></property>
</bean>
</beans>
05-11 13:55