基于 MVC 三层架构,Spring 配置文件(08.10.31号)
2008-10-31 11:28
351 查看
<?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>
相关文章推荐
- spring+springMVC+mybatis整合示例(基于XML配置文件)
- SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释
- spring+springmvc+mybatis中的xml配置文件详解
- ExtDirectSpring配置(基于ExtJs4 MVC)
- 基于spring的web项目中一些配置文件的解释
- Spring MVC + Mybatis 配置文件模板
- mybatis与spring整合(基于配置文件)
- 基于Spring3 MVC实现基于form表单上传Excel文件,批量导入数据时,报错:Unable to recognize OLE stream !
- Spring4学习笔记-AOP(基于配置文件的方式)
- springmvc+mybatis下基于注解的Atomikos分布式事务配置
- Spring+SpringMVC+MyBatis深入学习及搭建(三)之MyBatis全局配置文件解析
- 【Hibernate】【配置文件】【基于Spring】
- spring(一)--spring/springmvc/spring+hibernate(mybatis)配置文件
- SSM(SpringMVC+Spring+MyBatis) 配置文件
- spring的配置文件中mvc:view-controllerpath使用方法
- exit-web-framework基于Spring 3、Hibernate4框架来对做项目核心三层和MVC的管理
- 三层架构——配置文件
- mybatis与spring整合(基于配置文件)
- 基于MVC三层架构结合自己理念生成的四层架构
- Spring Cloud Spring Boot mybatis分布式微服务云架构(四)属性配置文件详解(2)