In the Spring to configure Service

sponsored links
JTA in Spring

Development Environment: JDK1.5 (sun) + Myeclipse6.0 + Tomcat5.5 + ant 1.7.1 + MySql5.0.4

Framework version: JSF1.2 (sun) + hibernate3.3.1.GA + spring2.5.6

JTA (Java Transaction API)

Only supports the standard EJB Persistence (JTA) transaction management, and Spring can support the most popular persistence framework for transaction management.

In the Spring, through implementation org.springframework.transaction.PlatformTransactionManager interface to achieve a variety of persistence frameworks affairs.

Programs persistent

Spring to configure affairs that corresponds to category









Spring's transaction manager to provide only the implementation of existing Services API (Hibernate, JDBC, JTA) package, which itself does not provide specific services to achieve.

In the Spring of affairs org.springframework.transaction.TransactionDefinition interface definition. If you want a deeper understanding of the affairs Sping mechanism, it is necessary to understand the interface.

Spring in the spread of property would support a total of seven, can refer to Pok Man " Spring in the affairs of the dissemination of detailed property "And" doubts spring nested transaction "

If I want to achieve the following requirements: in a specific category, if the method name is insert, delete at the beginning of the method to support the safety of current affairs, if there is no current affairs, on the construction of a new services, other methods read-only.

Introduce the following requirements on the above two in the Spring configuration commonly used in the affairs of Ways:

Method 1: Using BeanNameAutoProxyCreator automatically create Service agent

<!--  -->
<bean  >
       <property name="sessionFactory" ref="sessionFactory" />

<!-- Define transaction rules interceptor -->
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
           <prop key="insert*">PROPAGATION_REQUIRED</prop>
           <prop key="delete*">PROPAGATION_REQUIRED </prop>
           <prop key="*">readOnly</prop>
<!-- Add to implement the transaction rules of BeanName -->
    <property name="beanNames">
    <property name="interceptorNames">

<bean     >
    <property name="sessionFactory" ref="sessionFactory" />

    <property name="hibernateTemplate" ref="hibernateTemplate" />

Method II: Using AOP to manage the affairs Principle

With the large quantity Sping project code, you will find more and more to many configurations, and cumbersome. In Sping2.0 after, Sping introduced a simplified XML configuration. Concrete can look white Jiangnan " Simplify the Spring - configuration file . "

In use before the Second, add packages required packages as follows: aspectjrt.jar, aspectjweaver.jar

ApplicationContext.xml and the head are defined as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    xmlns:aop=""   xmlns:context=""

Then configure Affairs

<bean  >
    <property name="sessionFactory" ref="sessionFactory" />

<!-- This configuration has thought of AOP, looking for this surface is com .sms.freeborders.dao.hbimplAll of the classes under -->

       expression="execution(* com.sms.freeborders.dao.hbimpl.*.*(..))" />
    <aop:advisor advice-ref="txAdvice"
       pointcut-ref="allManagerMethod" />

<!-- Configure transaction rules -->

       <tx:method name="insert *" />
       <tx:method name="delete*" />
       <tx:method name="*" read-only="true" />

<bean  >
       <property name="sessionFactory" ref="sessionFactory" />

    <property name="hibernateTemplate" ref="hibernateTemplate" />
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of In the Spring to configure Service

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • 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; 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 *

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @

  • 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 Entries
Tag Cloud
Random Entries