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)
最新推荐文章于 2017-09-05 18:18:00 发布