About Struts + hibernate + Spring integration

sponsored links
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 ->
<context-param>
<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>
<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>
<filter-name> characterEncodingFilter </ filter-name>
<filter-class> org.springframework.web.filter.Charact [color = brown] [/ color] erEncodingFilter </ 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>
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>
<filter-name> hibernate session manager filter </ filter-name>
<filter-class> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </ filter-class>
</ filter>

<filter-mapping>
<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 ->
<bean>
<property name="sessionFactory" ref="sessionFactory" />
</ bean>

<! - Configuration Advice (affairs propagation) ->
<tx:advice transaction-manager="transactionManager">
<tx:attributes>
<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:config>
<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:
java.lang.NoSuchMethodError:
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.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of About Struts + hibernate + Spring integration

  • Nan-Jing 5: When IBatis.Hibernate mixed affairs, pay attention to your SQL

    [Problem] Now, in the development of the so-called multi-storey JavaEE applications, data persistence layer is always essential, and "Automatic" of ORM - Hibernate, and "all-manual-type" of SqlMap - IBatis, equivalent data are Per ...

  • Hibernate connection pool configuration

    Hibernate connection pool configuration <! - Jdbc -> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </ property> <property name="connection.url"> jdbc: oracle: thin: @ 10.203.14.132:15

  • hibernate to use the principle of

    The use of hibernate, implementation of data persistence. Has the following several processes. One configuration database connection information. Hibernate.config 2 configuration mapping. 3 use: the use of the process are the following steps: 3.1: Ge ...

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

  • Based on JDBC, JPA Annotation achieve simple CRUD Generic Dao

    The origin of ideas are pretty long history of reasons: [Use iBATIS history] The use of iBATIS has been a long time, the system is to use the CRUD template tool to generate the code, although there are tools to generate, but looked at a lot of CRUD the Sq

  • Hibernate secondary cache

    Hibernate cache: 2-bit cache, also known as process-level cache or SessionFactory level cache, secondary cache can be shared by all of the session Cache configuration and the use of: Will echcache.xml (the document code in hibernate package directory ...

  • Hibernate's lazy strategy

    hibernate Lazy strategy can be used in: <class> tag, it can be true / false Tags can <PROPERTY> values true / false type of necessary tools to enhance <set> <list> can tag values true / false / extra <many-to-one> <on ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries