<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/goodhope" />
<property name="username" value="goodhope" />
<property name="password" value="goodhope" />
</bean>
<!-- Hibernate_SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocations">
<list>
<value>
classpath:hibernate.cfg.xml
</value>
</list>
</property>
</bean>
<!-- Hibernate_事务代理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- DAO 实现层,并将其注入SessionFactory -->
<bean id="userDaoImpl" class="com.goodhope.dao.impl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- SpringAOP 对 DAO 接口的动态代理 -->
<bean id="userDAOProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.goodhope.dao.UserDao</value>
</property>
<property name="target">
<ref bean="userDaoImpl" />
</property>
</bean>
<!-- 业务层接口实现,把DAO注入到Service里面 -->
<bean id="userServiceTarget" class="com.goodhope.service.impl.UserServiceImpl">
<property name="userDao">
<ref bean="userDAOProxy" />
</property>
</bean>
<!-- spring代理业务层的事务管理 -->
<bean id="userService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly
</prop>
</props>
</property>
<property name="proxyInterfaces">
<list>
<value>
com.goodhope.service.UserService
</value>
</list>
</property>
<property name="target">
<ref bean="userServiceTarget" />
</property>
</bean>
<!-- 配置struts访问,把service层注入到Action里面 -->
<bean id="userAction" class="com.goodhope.action.UserAction"
scope="prototype">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/goodhope" />
<property name="username" value="goodhope" />
<property name="password" value="goodhope" />
</bean>
<!-- Hibernate_SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocations">
<list>
<value>
classpath:hibernate.cfg.xml
</value>
</list>
</property>
</bean>
<!-- Hibernate_事务代理 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- DAO 实现层,并将其注入SessionFactory -->
<bean id="userDaoImpl" class="com.goodhope.dao.impl.UserDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- SpringAOP 对 DAO 接口的动态代理 -->
<bean id="userDAOProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.goodhope.dao.UserDao</value>
</property>
<property name="target">
<ref bean="userDaoImpl" />
</property>
</bean>
<!-- 业务层接口实现,把DAO注入到Service里面 -->
<bean id="userServiceTarget" class="com.goodhope.service.impl.UserServiceImpl">
<property name="userDao">
<ref bean="userDAOProxy" />
</property>
</bean>
<!-- spring代理业务层的事务管理 -->
<bean id="userService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly
</prop>
</props>
</property>
<property name="proxyInterfaces">
<list>
<value>
com.goodhope.service.UserService
</value>
</list>
</property>
<property name="target">
<ref bean="userServiceTarget" />
</property>
</bean>
<!-- 配置struts访问,把service层注入到Action里面 -->
<bean id="userAction" class="com.goodhope.action.UserAction"
scope="prototype">
<property name="userService">
<ref bean="userService" />
</property>
</bean>
</beans>