struts_spring_hibernate集成
2009-02-15 22:21
429 查看
好了,ssh手动集成完成,也不知道怎么说,就是把前2个集成,放在一起。
先实现struts和spring,再实现hibernate和spring。
因为显示层和持久层关系不大。主要是通过业务层沟通起来。
核心还是spring,很好很强大。
这里有3个spring的配置文件:
applicationContext-actions.xml ---- 配置spring对struts中的路径和类;
applicationContext-beans.xml ---- 配置spring的IoC对类的管理;
applicationContext-common.xml --- 配置hibernate的sessionFactory和事务注入spring的IoC管理;
配置web.xml也so重要:
<!-- 将struts的核心控制器配置进容器 -->
<servlet>
<servlet-name>actionServlet</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>actionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 将spring的配置文件装载入web容器中 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 通过filter设置程序编码为gbk -->
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置 一个为了避免hibernate懒加载异常而创建的解决方案 进入容器 -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意2个地方别写错了:
1、在applicationContext-common.xml中:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
这里面的classpath,在客户端或者junit测试中能通过。
但是在web项目中就出错了,是在读取sessionFactory的时候出错。
2、在web.xml中:
spring的配置文件通过监听(listener)载入web容器中,那么代码是:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
其中的classpath也是不能丢的。
剩下我就把这几个spring中的包装类罗列出来:
org.springframework.orm.hibernate3.LocalSessionFactoryBean
本地的sessionFactory类 -- 加载SessionFactory
org.springframework.web.context.ContextLoaderListener
上下文加载监听 -- 加载applicationContext.xml
org.springframework.web.filter.CharacterEncodingFilter
字符编译过滤
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
处理session的lazy异常
org.springframework.orm.hibernate3.HibernateTransactionManager
hibernate事务管理器
org.springframework.web.struts.DelegatingActionProxy
代理action类 -- spring的包装类作用:1、取得BeanFactory。2、根据path找到IoC中的业务控制器(自己写的Action)
大概基本上就这几个了
so easy!
先实现struts和spring,再实现hibernate和spring。
因为显示层和持久层关系不大。主要是通过业务层沟通起来。
核心还是spring,很好很强大。
这里有3个spring的配置文件:
applicationContext-actions.xml ---- 配置spring对struts中的路径和类;
applicationContext-beans.xml ---- 配置spring的IoC对类的管理;
applicationContext-common.xml --- 配置hibernate的sessionFactory和事务注入spring的IoC管理;
配置web.xml也so重要:
<!-- 将struts的核心控制器配置进容器 -->
<servlet>
<servlet-name>actionServlet</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>actionServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 将spring的配置文件装载入web容器中 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- 通过filter设置程序编码为gbk -->
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置 一个为了避免hibernate懒加载异常而创建的解决方案 进入容器 -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意2个地方别写错了:
1、在applicationContext-common.xml中:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
</bean>
这里面的classpath,在客户端或者junit测试中能通过。
但是在web项目中就出错了,是在读取sessionFactory的时候出错。
2、在web.xml中:
spring的配置文件通过监听(listener)载入web容器中,那么代码是:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
其中的classpath也是不能丢的。
剩下我就把这几个spring中的包装类罗列出来:
org.springframework.orm.hibernate3.LocalSessionFactoryBean
本地的sessionFactory类 -- 加载SessionFactory
org.springframework.web.context.ContextLoaderListener
上下文加载监听 -- 加载applicationContext.xml
org.springframework.web.filter.CharacterEncodingFilter
字符编译过滤
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
处理session的lazy异常
org.springframework.orm.hibernate3.HibernateTransactionManager
hibernate事务管理器
org.springframework.web.struts.DelegatingActionProxy
代理action类 -- spring的包装类作用:1、取得BeanFactory。2、根据path找到IoC中的业务控制器(自己写的Action)
大概基本上就这几个了
so easy!
相关文章推荐
- 传智播客-spring2.5(5)-struts、spring、hibernate集成
- Spring+struts+hibernate 集成方案
- Spring如何集成struts和hibernate
- Struts2.3.4+Hibernate3.6+Spring2.5.6 集成教程
- S2SH框架集成详解(Struts 2.3.16 + Spring 3.2.6 + Hibernate 3.6.10)
- Ssh为 struts+spring+hibernate的一个集成框架
- Struts + Spring + Hibernate集成
- S2SH框架集成(Struts 2.3.16 + Spring 3.2.6 + Hibernate 3.6.10)
- Struts,Hibernate,Spring集成开发宝典
- spring+struts+hibernate集成环境(基于maven项目搭建)
- hibernate+spring+struts集成,并自动生成实体类和DAO层的步奏
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--案例结构
- spring3.1.1与hibernate4.1.5与struts2.3.4集成
- Struts 2 + Spring + Hibernate 集成
- osgi与流行的框架(spring,struts,hibernate等)的集成
- 集成 Hibernate,Spring,Struts Portlet 框架构建 Portlet 应用
- Spring 3.1, Struts 2, Hibernate 3.5集成
- spring与struts、hibernate的集成
- Struts2.1&Hibernate3.2&Spring2.5集成[基于Annotation]--代码
- Struts+Spring+Hibernate (一) 集成原理和搭建环境