About Struts + hibernate + Spring integration

Struts, Spring and hibernate integration:
1, in the spring to support the project to import, import Jar package has:
* Spring 2.0 Core Libraries
* Spring 2.0 ORM/DAO/Hibernate3 Libraries
* Spring 2.0 AOP Libraries
* Spring 2.0 Web Libraries
2, in the Spring configuration file to configure dataSource and SessionFactory, will hibernate configuration together with the Spring configuration (hibernate.cfg.xml file can be deleted);
3, import the source database to be used for Jar package, such as: DBCP used JAR package (commons-pool.jar);
4, modify all the DAO implementation of hibernate, because Spring provides a HibernateDAOSupport Medium category, the database can be simplified operation. The use of all types of DAO are inherited from the type;
5, will be used DAO dependency injection into the Biz of the way in, and then the use of dependency injection Biz way into Action, in the Spring configuration file to do the appropriate configuration;
6 to Spring and Struts integration:
1) In the spring configuration file to configure Action: to be injected into the Action Medium Biz;
2) Revise the Struts configuration file: Action of the type property will be amended as: org.springframework.web.struts.DelegatingActionProxy;
3) In the web.xml file to configure, and monitor web application initialization parameters:
<! - Listener class to pass initialization parameters to obtain beanFactory object ->
<param-name> contextConfigLocation </ param-name>
<param-value> / WEB-INF/applicationContext.xml / WEB-INF/applicationContext-beans.xml </ param-value>
</ context-param>

<! - The use of the Spring listener initialization beanFactory, and put into Context, in use when it removed to obtain the IOC container bean ->
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>
7, in order to solve the application problem of Chinese characters, we can not have their own category filters, Spring has provided us with one click only need to configure:
<! - The use of Spring in the filter to solve the Chinese problem garbled ->
<filter-name> characterEncodingFilter </ filter-name>
<filter-class> org.springframework.web.filter.Charact [color = brown] [/ color] erEncodingFilter </ filter-class>
<param-name> encoding </ param-name>
<param-value> UTF-8 </ param-value>
</ init-param>
</ filter>

<filter-name> characterEncodingFilter </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>
8, in order to solve the problem of hibernate lazy loading, the use of Spring to provide the filters to solve, it can allow Session
At the request of explanation after the completion of turn off, configure as follows:
<! - Hibernate lazy loading solution brought about by abnormal configuration filter allows the completion of Session at the request of then turn off ->
<filter-name> hibernate session manager filter </ filter-name>
<filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </ filter-class>
</ filter>

<filter-name> hibernate session manager filter </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>
9, getSession because OpenSessionInViewFilter at the time of the session will obtain the return of the flush mode set to FlushMode.NEVER. Therefore, to insert,
update and delete operation will produce abnormal: org.springframework.dao.InvalidDataAccessApiUsageException:
Write operations are not allowed in read-only mode (FlushMode.NEVER / MANUAL): Turn your Session into FlushMode.COMMIT / AUTO or remove 'readOnly' marker from transaction definition.
Spring therefore necessary to adopt a statement of affairs, so that by the Ways transaction control:
<! - Configure the transaction manager ->
<property name="sessionFactory" ref="sessionFactory" />
</ bean>

<! - Configuration Advice (affairs propagation) ->
<tx:advice transaction-manager="transactionManager">
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="search*" propagation="SUPPORTS" read-only="true"/>
</ tx: attributes>
</ tx: advice>

<! - Configure the transaction manager application scope ->
<aop:pointcut expression="execution(* edu.accp.dao.hibImpl.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="affectMethods"/>
</ aop: config>
10, the deployment of applications, restart the server, if abnormal:
org.objectweb.asm.ClassVisitor.visit (IILjava / lang / String; Ljava / lang / String; [Ljava / lang / String; Ljava / lang / String;) V
This is because when Jar package integration of conflict-induced. Should be "Web application / WEB-INF/lib/asm-2.2.3.jar" to delete.

分类:Java 时间:2009-03-30 人气:803
blog comments powered by Disqus


  • servlet in the web.xml configuration file parameters in context-param and the init-param District 2010-06-17

    web.xml which can be defined two parameters: (1) application within the parameters stored in servletcontext, in web.xml, configured as follows: <context-param> <param-name> context / param </ param-name> <param-value> avalible duri

  • Access to context-param in web.xml and init-param parameter 2010-03-19

    web.xml which can be defined two kinds of parameters: (1) application within the parameters stored in the servletcontext, in the web.xml to configure the following: xml code <context-param> <param-name> context / param </ param-name> <

  • 解析web.xml中在Servlet中获取context-param和init-param内的参数 2013-11-20

    本篇文章是对web.xml中在Servlet中获取context-param和init-param内的参数进行了详细的分析介绍,需要的朋友参考下 web.xml里面可以定义两种参数:1.application范围内的参数,存放在servletcontext中,在web.xml中配置如下: <context-param> <param-name>context/param</param-name> <param-value>avalible during ap

  • Xiang Jie Struts configuration file, web.xml and struts-cofig.xml, as well as the struts-cofig.xml in the role of the various labels 2010-04-19

    Struts applications use two XML-based configuration files to configure, respectively web.xml and struts-cofig.xml file. Web.xml file is the configuration for all web applications, while the struts-config.xml file is struts-specific configuration file

  • Excellent tools Spring Part 1 file resource inventory operations and Web-related tools 2010-11-21

    Suppose there is a resource to access files in the Web application files to the class path, you can in the following ways to access resources on this file: • By FileSystemResource absolute path to the file system access way; • By ClassPathResource wa

  • context-param and different init-param 2010-09-16

    web.xml which can be defined two parameters: (1) application within the parameters stored in servletcontext, in web.xml, configured as follows: <context-param> <param-name> context / param </ param-name> <param-value> avalible duri

  • context-param and the difference between init-param 2011-05-23

    web.xml which can define two parameters: (1) application within the parameters stored in servletcontext, in web.xml, configured as follows: <context-param> <param-name>context/param</param-name> <param-value>avalible during applica

  • context-param to use 2010-06-17

    web.xml to set parameters <context-param> <param-name> ENCODE </ param-name> <param-value> utf-8 </ param-value> </ Context-param> The procedure for obtaining parameters HttpServletRequest hsr = (HttpServletRequest) req

  • ASP.NET中根据XML动态创建使用WEB组件 2014-04-13

    前段时间笔者在开发中需要动态创建WEB组件,本以为是小事一桩,谁知看时容易做时难.里面还真有些小问题.下面笔者就结合自己的程序来介绍一下如何动态创建并使用WEB组件,希望能给做类似工作的朋友提供一点帮助. 一.程序思路 程序主要分三部分: 1.程序要根据XML中的数据信息确定需要创建的WEB组件的个数. 2.动态创建WEB组件. 3.使用动态创建的WEB组件. 其中2和3是笔者要重点介绍的部分. 下面笔者就按照这三部分结合程序实例(以c#为例)来一一介绍. 二.读取XML文件 读取XML文件在很

  • web.xml in the load-on-startup tag meaning and application of struts jstl 2009-09-10

    Among the servlet configuration ,<load-on-startup>5</load-on-startup> Mean : Tag container is in the started loading this servlet. Where a value of 0 or greater than 0 Represents a container when the application starts the load servlet: When i

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.520 (s). 14 q(s)