Unite the framework of SSH2

The first step:

import  the package ofStruts2,Hibernate andSpring


The next step:

Create (log4j.properties) or (struts.xml)  under  the  src  of  your project

            

And ought to set the struts.xml 's constant be like that <constant name="struts.objectFactory" value="spring"/>


The next step:

Config the web.xml under WEB_INT of your project

<!-- Spring框架的配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- 这里可以添加多个配置文件,以‘,’隔开 -->
<param-value>/WEB-INF/applicationContext-*.xml</param-value>
</context-param>


<!-- 启动Spring声明生命周期的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!-- 解决中文乱码 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 解决web项目中session延迟加载问题的配置 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filterclass>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

</filter-class>

</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Struts2核心过滤器的配置 -->
<filter>
<filter-name>Struts2</filter-name>
<filterclass>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


</web-app>
 


The next step:

Create applicationContext-beans.xml,applicationContext-db.xml and applicationContext-tx.xml under the folder of WEB_INF

                           

applicationContext-db.xml: This file was used to set dataSource 

Tips:  Here ought to import a package of c3p0.jar


The next step:

Config the applicationContext-tx.xml:

What needs to be modified here was: <bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

 There was my file's content:

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">


<property name="dataSource" ref="dataSource" />
<!-- 映射User.hbm.xml -->
<property name="mappingResources">
<list>
<value>com/xunpoit/entity/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.format_sql=false
 </value>
</property>


</bean>


The last step:

Config the applicationContext-beans.xml:

It was AOP of the Spring




Thank for your read

Author:lzq_blog

Date:2016-10-07



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值