spring1.1和2.0中aop建议配置
1.spring1.1
- <? 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.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >
- < bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" >
- < property name = "driverClassName" value = "com.mysql.jdbc.Driver" />
- < property name = "url" value = "jdbc:mysql://localhost:3306/eimhe" />
- < property name = "username" value = "root" />
- < property name = "password" value = "ok" />
- </ bean >
- < bean id = "sessionFactory"
- class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
- < property name = "dataSource" ref = "dataSource" />
- < property name = "mappingResources" >
- < list >
- < value > org/springframework/lesson4/Person.hbm.xml </ value >
- </ list >
- </ property >
- < property name = "hibernateProperties" >
- < props >
- < prop key = "hibernate.dialect" >
- org.hibernate.dialect.MySQLDialect
- </ prop >
- </ props >
- </ property >
- </ bean >
- < bean id = "dao" class = "org.springframework.lesson4.PersonDAO" >
- < property name = "sessionFactory" ref = "sessionFactory" />
- </ bean >
- < bean id = "transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
- < property name = "sessionFactory" ref = "sessionFactory" />
- </ bean >
- < bean id = "personProxy" class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
- < property name = "transactionManager" ref = "transactionManager" />
- < property name = "proxyInterfaces" >
- < list >
- < value > org.springframework.lesson4.IPersonDAO </ value >
- </ list >
- </ property >
- < property name = "target" ref = "dao" />
- < property name = "transactionAttributes" >
- < props >
- < prop key = "getAll*" > PROPAGATION_REQUIRED </ prop >
- </ props >
- </ property >
- </ bean >
- </ beans >
<?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.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/eimhe"/>
<property name="username" value="root" />
<property name="password" value="ok"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>org/springframework/lesson4/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
</bean>
<bean id="dao" class="org.springframework.lesson4.PersonDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="personProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="proxyInterfaces">
<list>
<value>org.springframework.lesson4.IPersonDAO</value>
</list>
</property>
<property name="target" ref="dao" />
<property name="transactionAttributes">
<props>
<prop key="getAll*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
2.spring2.0
- <? 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.0.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >
- < bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" >
- < property name = "driverClassName" value = "com.mysql.jdbc.Driver" />
- < property name = "url" value = "jdbc:mysql://localhost:3306/eimhe" />
- < property name = "username" value = "root" />
- < property name = "password" value = "ok" />
- </ bean >
- < bean id = "sessionFactory"
- class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
- < property name = "dataSource" ref = "dataSource" />
- < property name = "mappingResources" >
- < list >
- < value > org/springframework/lesson4/Person.hbm.xml </ value >
- </ list >
- </ property >
- < property name = "hibernateProperties" >
- < props >
- < prop key = "hibernate.dialect" >
- org.hibernate.dialect.MySQLDialect
- </ prop >
- </ props >
- </ property >
- </ bean >
- < bean id = "dao" class = "org.springframework.lesson4.PersonDAO" >
- < property name = "sessionFactory" ref = "sessionFactory" />
- </ bean >
- < bean id = "transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
- < property name = "sessionFactory" ref = "sessionFactory" />
- </ bean >
- < tx:advice id = "txAdvice" transaction-manager = "transactionManager" >
- < tx:attributes >
- < tx:method name = "getAllPersons" propagation = "REQUIRED" />
- </ tx:attributes >
- </ tx:advice >
- < aop:config >
- < aop:pointcut id = "personPointer" expression = "execution(* org.springframework.lesson4.IPersonDAO.*(..))" />
- < aop:advisor advice-ref = "txAdvice" pointcut-ref = "personPointer" />
- </ aop:config >
- </ beans >