struts+hibernate+spring整合
2008-12-12 21:55
357 查看
在web.xml中
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config/spring-dao.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
在struts-config.xml中用spring进行请求转发
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>
并把spring IOC配置文件spring-bean.xml在启动时加载
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/spring-config/spring-bean.xml" />
</plug-in>
在spring-dao.xml中
<?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.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/logis</value>
</property>
</bean>
<!-- sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>cn/com/csu/vo/UserVo.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- 模板 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<constructor-arg>
<ref local="sessionFactory"/>
</constructor-arg>
</bean>
<!-- 事务管理 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 代理设置 -->
<bean id="daoProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="hibernateTransactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<!-- DAO配置 -->
<bean id="LoginDaoImpl" parent="daoProxy">
<property name="target">
<bean class="cn.com.csu.dao.impl.LoginDaoImpl">
<property name="hibernateTemplate">
<ref local="hibernateTemplate"/>
</property>
</bean>
</property>
</bean>
</beans>
在spring-bean.xml中
<?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"
default-lazy-init="true"
>
<bean id="LoginServiceImpl" class="cn.com.csu.service.impl.LoginServiceImpl">
<property name="loginDaoImpl">
<ref bean="LoginDaoImpl"/>
</property>
</bean>
<bean name="/login" class="cn.com.csu.action.LoginAction">
<property name="loginServiceImpl">
<ref local="LoginServiceImpl"/>
</property>
</bean>
</beans>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config/spring-dao.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
在struts-config.xml中用spring进行请求转发
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>
并把spring IOC配置文件spring-bean.xml在启动时加载
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/spring-config/spring-bean.xml" />
</plug-in>
在spring-dao.xml中
<?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.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/logis</value>
</property>
</bean>
<!-- sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>cn/com/csu/vo/UserVo.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- 模板 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<constructor-arg>
<ref local="sessionFactory"/>
</constructor-arg>
</bean>
<!-- 事务管理 -->
<bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 代理设置 -->
<bean id="daoProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="hibernateTransactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<!-- DAO配置 -->
<bean id="LoginDaoImpl" parent="daoProxy">
<property name="target">
<bean class="cn.com.csu.dao.impl.LoginDaoImpl">
<property name="hibernateTemplate">
<ref local="hibernateTemplate"/>
</property>
</bean>
</property>
</bean>
</beans>
在spring-bean.xml中
<?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"
default-lazy-init="true"
>
<bean id="LoginServiceImpl" class="cn.com.csu.service.impl.LoginServiceImpl">
<property name="loginDaoImpl">
<ref bean="LoginDaoImpl"/>
</property>
</bean>
<bean name="/login" class="cn.com.csu.action.LoginAction">
<property name="loginServiceImpl">
<ref local="LoginServiceImpl"/>
</property>
</bean>
</beans>
相关文章推荐
- Spring2.5+Struts1.3.8+Jpa(Hibernate实现)整合之七
- 在进行maven+spring+struts+hibernate整合时发生class path resource [spring.xml] cannot be opened because it do
- 用maven整合struts+spring+hibernate之二 数据库生成和测试数据
- Struts Spring Hibernate 框架整合时候出现的问题
- Struts、Spring、Hibernate之间的整合方式
- struts+hibernate+spring的整合
- (转)最新版的SSH框整合(Spring 3.1.1 + Struts 2.3.1.2 + Hibernate 4.1)
- Spring2.5+Struts1.3.8+JPA(Hibernate实现)整合之五
- Struts+Spring+Hibernate整合入门详解
- Struts+Spring+Hibernate 整合笔记
- spring+struts2+hibernate整合(ssh)
- spring整合struts,hibernate annotation(pool数据池,sqlserver2005数据库)
- struts-2.3、spring2.5.6、hibernate3.3整合
- struts+hibernate+spring整合过程常见问题收集
- Struts+Spring+Hibernate/SSH整合开发详细二
- Struts、Spring、hibernate的整合
- Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2 整合总结
- 浅谈ssh(struts,spring,hibernate三大框架)整合的意义及其精髓