Spring declarative transaction configuration method (4): beannameautoproxycreator injects Bean

Source: Internet
Author: User

 

<? XML version = "1.0" encoding = "UTF-8"?>

<Beans xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xmlns: AOP = "http://www.springframework.org/schema/aop"
Xmlns: Tx = "http://www.springframework.org/schema/tx"
Xsi: schemalocation ="
Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">
<Bean id = "testaction" class = "test. Action. stuts2actiontest">
<Property name = "service" ref = "templatesservice"> </property>
</Bean>

<Bean id = "templatesservice"
Class = "test. Service. impl. taotemplatesserviceimpl">
<Property name = "Dao" ref = "templatesdao"/>
</Bean>

<Bean id = "templatesdao" class = "test. Dao. impl. taotemplatesdaoimpl">
<Property name = "sessionfactory" ref = "sessionfactory"> </property>
</Bean>

<! -- Define a data source -->
<Bean id = "datasource"
Class = "org. Apache. commons. DBCP. basicdatasource">
<! -- Define a database driver -->
<Property name = "driverclassname">
<Value> oracle. JDBC. Driver. oracledriver </value>
</Property>
<! -- Define Database URL -->
<Property name = "url">
<Value> JDBC: oracle: thin: @ 192.168.1.96: 1521: yxdb </value>
</Property>
<! -- Define database username -->
<Property name = "username">
<Value> yxuser </value>
</Property>
<! -- Define Database Password -->
<Property name = "password">
<Value> yxuser </value>
</Property>
</Bean>

<! -- Define a sessionfactory of hibernate -->
<Bean id = "sessionfactory"
Class = "org. springframework. Orm. hibernate3.localsessionfactorybean">
<! -- Defines that sessionfactory must be injected with datasource -->
<Property name = "datasource">
<Ref local = "datasource"/>
</Property>
<Property name = "mappingresources">
<List>
<! -- The following is used to list all po ing files -->
<Value> test/mapping/tao_templates.hbm.xml </value>
</List>
</Property>
<Property name = "hibernateproperties">
<Props>
<Prop key = "hibernate. dialect">
Org. hibernate. dialect. oracle10gdialect
</Prop>
<Prop key = "hibernate. show_ SQL"> true </prop>
<! -- The attribute of sessionfactory of Hibernate is defined here:
For different database connections, select create, update, create-drop -->
<Prop key = "hibernate. hbm2ddl. Auto"> Update </prop>
</Props>
</Property>
</Bean>

<! -- Define the Transaction Manager and use the Transaction Manager for hibernte -->
<Bean id = "transactionmanager"
Class = "org. springframework. Orm. hibernate3.hibernatetransactionmanager">
<! -- Hibernatetransactionmanager Bean must be referenced by injecting a sessionfactory bean dependency -->
<Property name = "sessionfactory">
<Ref local = "sessionfactory"/>
</Property>
</Bean>

<! -- Configure the transaction interceptor -->
<Bean id = "transactioninterceptor"
Class = "org. springframework. transaction. Interceptor. transactioninterceptor">
<! -- The transaction interceptor bean needs to inject a Transaction Manager dependency -->
<Property name = "transactionmanager" ref = "transactionmanager"/>
<Property name = "transactionattributes">
<! -- The following defines the transaction propagation attribute -->
<Props>
<! -- All Methods Starting with add adopt the required transaction policy and read-only -->
<Prop key = "add *"> propagation_required, readonly </prop>
<! -- All Methods Starting with Mod adopt the required transaction policy and read-only -->
<Prop key = "Mod *"> propagation_required, readonly </prop>
<! -- All Methods Starting with Del adopt the required transaction policy and read-only -->
<Prop key = "del *"> propagation_required, readonly </prop>
<! -- Other Methods: Use the required transaction policy -->
<Prop key = "*"> readonly </prop>
</Props>
</Property>
</Bean>

<! -- Defines beannameautoproxycreator. This bean is a bean post-processor and does not need to be referenced. Therefore, there is no ID attribute.
The post-processor of this bean automatically creates a transaction proxy for the target bean Based on the transaction interceptor -->
<Bean
Class = "org. springframework. AOP. Framework. autoproxy. beannameautoproxycreator">
<! -- Specify which bean names are used to automatically generate a Service proxy -->
<Property name = "beannames">
<! -- The following are all the beans that need to automatically create the transaction proxy -->
<List>
<! --
-->
<Value> persondao </value>
</List>
<! -- Here, you can add other beans that require automatic transaction proxy creation. -->
</Property>
<! -- The following defines the transaction interceptor required by beannameautoproxycreator -->
<Property name = "interceptornames">
<List>
<Value> transactioninterceptor </value>
<! -- Other new interceptor can be added here -->
</List>
</Property>
</Bean>
</Beans>

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.