Using Open Source Product Assembly Your Web Application Schema (3) Reproduction

xiaoxiao2021-03-06  59

Here is the configuration of HibernateSessionFactory and HibernateTransactionManager:

Class = "org.springframework.orm.hibernate.

LocalSessionFactoryBean>>

COM / meage / bo / order.hbm.xml

COM / MeAgle / Bo / OrderLineItem.hbm.xml

Net.sf.hibernate.Dialect.MysqldiaLect

False

C: / myWebapps /.../ Web-inf / proxool.xml

Spring

SessionFactory (Alternative to JTA) ->

Class = "ORG.

Springframework.

ORM.

Hibernate.

HibernateTransactionManager ">

It can be seen that each object can be referenced in the Spring configuration information. Here, MySessionFactory references HibernateSessionFactory, and MyTransactionManager references HibernateTransactionManage. Note that the MyTransactionManger Bean in the code has a sessionFactory property. HibernateTransactionManager has a SessionFactory Setter and getter method, which is used to implement "dependency injection" when Spring starts. Quote MySessionFactory in the SessionFactory property. These two objects were assembled after the Spring container was initialized. Such a match allows you to liberate from the Singleton Objects and Factories, which reduces the maintenance cost of the code. The two properties of MySessionFactory. are used to inject mappingResources and HibernateProperties. Usually, if you use Hibernate outside Spring, such settings should be placed in hibernate.cfg.xml. In any case, Spring provides a convenient way ----- In the Spring internal configuration, it has entered the configuration of Hibernate. If you want more information, you can check the Spring API. Since we have already assembled service beans, you need to assemble Business Service Object and Dao and distribute these objects to a transaction manager.

Configuration information in Spring:

Class = "ORG.

Springframework.

TRANSACTION.

Interceptor.

TransactionProxyFactoryBean>>

Propagation_Required, Readonly, -OrdeRexception

Propagation_Required, -OrdeRexception

Hibernate IMplementation ->

Class = "com.meagle.

SERVICE.

Spring.

ORDERSERVICESPRINGIMPL ">

Class = "COM.

Meagle.

SERVICE.

DAO.

Hibernate.

ORDERHIBERNATEDAO ">

Figure 4 is an outline of our objects. As can be seen, each object is contacted Spring and can be injected into other objects via Spring. Compare it to the Spring profile, observe the relationship between them

Figure 4. Spring is based on the configuration file, set each bean together.

This example uses a TransactionProxyFactoryBean, which defines a setTransactionManager (). This object is useful, he can very convenient to deal with what you declared, there is Service Object. You can define how to deal with the TransactionAttributes property. Want to know more or refer to TransactionAttributeEditor.

TransactionProxyFactoryBean has a setter. This will be referenced by our Business Service Object (ORDERTARGET), and the ORDERTARGET defines the business service layer, and it also has an attribute, referenced by setorderdao (). This property

Spring and beans have to pay attention to: beans can be created in two ways. These are all defined in single case mode (SINGTON) and prototype modes. The default approach is Singleton, which means that the shared instance will be bound. The prototype mode allows new instances to be created when Spring uses Beans. When each user needs to get the copy of their own bean, you should only use Prototype mode. (For more, please refer to the single sample and prototype mode in the design mode)

转载请注明原文地址:https://www.9cbs.com/read-118200.html

New Post(0)