SS1整合(Struts1.3Spring3.0/Spring2.5)
1. 除添加struts支持,spring支持外,添加springweb支持
2. 分两种方式使struts配置文件指向spring配置文件
a:使用使用插件(ContextLoaderPlugIn) 只需要在struts配置文件中加入:<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="classpath:applicationContext.xml" /> </plug-in>
b.用监听器的形式加载配置文件,在web.xml中加入:
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>
3.
3. 在struts配置文件中添加controller节点,就不需要修改配置文件的type属性:<controller processorClass=” org.springframework.web.struts.DelegatingReguestProcessor”> </controller>
SH整合(Spring3.0/Spring3.0Hibernate3.3)
1.配好数据库
2.给项目添加Hibernate支持
3.反向工程 POJO创建配置文件、并创建POJO类
4.给项目添加Spring支持(选择所需要的包)
5.反向工程 Hibernate 添加SpringDAO
6.在配置文件applicationContext.xml中添加数据源和sessionFactory 如下:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"> </property> <property name="url" value="jdbc:sqlserver://127.0.0.1:1433"></property> <property name="username" value="sa"></property> <property name="password" value="630923"></property> </bean> <bean id="sf" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="configLocation"> <value>file:src/hibernate.cfg.xml</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> </props> </property> </bean>这样就可以写测试类进行测试了。
SSH1整合(Struts1.3Spring3.0Hibernate3.3)
最新推荐文章于 2025-11-26 15:59:01 发布
本文介绍如何将Struts1.3与Spring3.0/Spring2.5(SS1)以及Spring3.0与Hibernate3.3(SH)进行整合。包括使用ContextLoaderPlugIn或ContextLoaderListener配置Spring,通过DelegatingRequestProcessor整合Struts与Spring,并配置数据源及SessionFactory实现持久层操作。
833

被折叠的 条评论
为什么被折叠?



