The configuration of four declarative transactions in spring

Source: Internet
Author: User
Tags aop inheritance

Configuration of four declarative transactions in spring there are two ideas that are important in the spring container, which is our common IOC and AOP, and if these two ideas are understood, it is very helpful for us to learn design patterns and programming, in the design pattern written by gang (GOF) in the United States, Many of them have been used in the minds of the IOC. Simply put is the thought of dependency injection. A common scenario: if you want to reuse functionality from another class in a class, we may think first of inheritance, if you know the idea of the IOC, I think you will not use inheritance, you will immediately think of the use of the function to extract, in the class we want to use only through the set method of simple injection can be, In fact, this use of the combination of objects instead of inheritance, so as not only to avoid a single inheritance, but also a good implementation of loose coupling. It also follows the design principle of object-oriented programming: Multi-use combination, less inheritance. Here are the benefits of both the IOC and the AOP ideas. I will not introduce. The next thing I want to say is that several common transaction configurations in spring are fully embodied in AOP and the IOC.

On the Han, formerly EJB in the Java EE development in the famous. It is because EJB provides a lot of service, and does not need us to develop, which uses most of the declarative transactions it provides. EJB plays a very important role in the development of Java EE before spring is present. It is also a major contributor to many project failures. The reason for this is that it is a framework for heavyweight, aggressive fees. The need for expensive server support, in addition to its testing is a headache. And spring is exactly the opposite of it. Spring is a lightweight, non-intrusive, open source framework. It provides declarative transactions that are more powerful and do not require container support. This attraction many people are willing to give up EJB and use spring. Let's get to the point.

The following two bean configurations are used below.

<!--define the transaction manager (declarative transaction)-->

<bean id= "TransactionManager"
class= " Org.springframework.orm.hibernate3.HibernateTransactionManager "
<property name=" Sessionfactory ">
<ref local= "sessionfactory"/>
</property>
</bean>
<!--******* business Logic layer (yes The front package for each DAO layer is mainly used in the << façade mode >>******
<bean id= "Fundservice"
class= com.jack.fund.service. Serviceimpl. Fundservice ""
<property name= "Operdao"
<ref bean= "Operatordao"/>
</property> ;    
<property name= "Producedao"
<ref bean= "Fundproducedao"/>
</property>
<property name= "Customerdao"
<ref bean= "Customerdao"/>
</property>
<propert Y name= "Accountdao"
<ref bean= "Accountdao"/>
</property>
<property name= "Funda" Ccountdao ""
<ref bean= "Fundaccountdao"/>
</property>
<property name= "Fundtransdao"
<ref bean= "Fundtransdao"/>
</property>
&L T;/bean>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.