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 人气:810
blog comments powered by Disqus


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

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

  • Flash + html - Web pass parameters to FLASH 2010-07-05

    First, do first a need to receive the Flash parameters Create a new Flash document named: Test.fla, in the first frame by adding the following code: / / Create three text fields and set properties _root.createTextField ("foo_txt", 1,0,0,16,16);

  • How do I get the same name in the web request parameters of the problem 2010-06-29

    1. For a form, the parameters may have duplicate names, like a lot of requests for an address with same name as the parameter. For example: model.jsp? Ids = 1 & ids = 2 & ids = 3. 2. Then the server ids to obtain this parameter, it will be an arra

  • How to get web request parameters of the problem in the Juna 2010-06-29

    1. For a form, the parameters may have duplicate names, like a lot of requests for an address with same name as the parameter. For example: model.jsp? Ids = 1 & ids = 2 & ids = 3. 2. Then the server ids to obtain this parameter, it will be an arra

  • web page parameters passed to the background when a garbled how.? 2008-07-13

    In the javascript function inside look at the use of escape conversion on it. window.open ( "arpenker.ftl? name = escape (Lee Dae-General)");

  • servlet init parameters和context init parameters的区别 2013-12-14

    Context init parameters 在web.xml中如下 <web-app ...> <context-param> <param-name>foo</param-name> <param-value>bar</param-value> </context-param> <!-- other stuff including servlet declarations --> </web-app

  • Spring3 file upload speed of your Web development 2010-10-15

    Article go to: URL: http://www.javabloger.com/article/spring-3-file-upload-example.html Spring1 came out to say the least subvert a small J2EE development, thoroughly beat the EJB, J2EE development will be simplified Spring2 after launch with a varie

  • WD - URL Parameters and Application Parameters 2010-12-10

    SAP help on this point: http://help.sap.com/saphelp_nw70/helpdata/en/7b/fb57412df8091de10000000a155106/content.htm To read the URL parameters, we need to the following code in the HANDLEDEFAULT method of the default window controller DATA: it_paramet

  • python web development framework - the Django development environment for interactive configuration 2010-03-05

    Introduction: In windows or other operating systems, we use manager.py shell for django interactive operation, as CMD operate very convenient, so we can bring in advanced interactive program manager.py now I am using DreamPie . Optional interactive p

  • Modify configuration files for rapid deployment weblogic web project 2010-04-18

    In addition to the background with the console to configure the publishing services, you can also directly modify the configuration file to distribution services. Edit Profile D: \ bea \ user_projects \ domains \ base_domain \ config \ config.xml Inc

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



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

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

processed in 0.481 (s). 10 q(s)