ITeye博客

spring1.1和2.0中aop建议配置

lovezzy · 2008-12-17 09:39 · spring · Markdown

1.spring1.1

 

 

Xml代码 复制代码

  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>
  2. < beans   xmlns = "http://www.springframework.org/schema/beans"
  3. xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop = "http://www.springframework.org/schema/aop"
  5. xmlns:tx = "http://www.springframework.org/schema/tx"
  6. xsi:schemaLocation ="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  8. http://www.springframework.org/schema/aop
  9. http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
  10. http://www.springframework.org/schema/tx
  11. http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >
  12. < bean   id = "dataSource"   class = "org.apache.commons.dbcp.BasicDataSource" >
  13. < property   name = "driverClassName"   value = "com.mysql.jdbc.Driver" />
  14. < property   name = "url"   value = "jdbc:mysql://localhost:3306/eimhe" />
  15. < property   name = "username"   value = "root"   />
  16. < property   name = "password"   value = "ok" />
  17. </ bean >
  18. < bean   id = "sessionFactory"
  19. class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
  20. < property   name = "dataSource"   ref = "dataSource" />
  21. < property   name = "mappingResources" >
  22. < list >
  23. < value > org/springframework/lesson4/Person.hbm.xml </ value >
  24. </ list >
  25. </ property >
  26. < property   name = "hibernateProperties" >
  27. < props >
  28. < prop   key = "hibernate.dialect" >
  29. org.hibernate.dialect.MySQLDialect
  30. </ prop >
  31. </ props >
  32. </ property >
  33. </ bean >
  34. < bean   id = "dao"   class = "org.springframework.lesson4.PersonDAO" >
  35. < property   name = "sessionFactory"   ref = "sessionFactory"   />
  36. </ bean >
  37. < bean   id = "transactionManager"   class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
  38. < property   name = "sessionFactory"   ref = "sessionFactory"   />
  39. </ bean >
  40. < bean   id = "personProxy"   class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
  41. < property   name = "transactionManager"   ref = "transactionManager" />
  42. < property   name = "proxyInterfaces" >
  43. < list >
  44. < value > org.springframework.lesson4.IPersonDAO </ value >
  45. </ list >
  46. </ property >
  47. < property   name = "target"   ref = "dao"   />
  48. < property   name = "transactionAttributes" >
  49. < props >
  50. < prop   key = "getAll*" > PROPAGATION_REQUIRED </ prop >
  51. </ props >
  52. </ property >
  53. </ bean >
  54. </ 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代码 复制代码

  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>
  2. < beans   xmlns = "http://www.springframework.org/schema/beans"
  3. xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop = "http://www.springframework.org/schema/aop"
  5. xmlns:tx = "http://www.springframework.org/schema/tx"
  6. xsi:schemaLocation ="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
  8. http://www.springframework.org/schema/aop
  9. http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
  10. http://www.springframework.org/schema/tx
  11. http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >
  12. < bean   id = "dataSource"   class = "org.apache.commons.dbcp.BasicDataSource" >
  13. < property   name = "driverClassName"   value = "com.mysql.jdbc.Driver" />
  14. < property   name = "url"   value = "jdbc:mysql://localhost:3306/eimhe" />
  15. < property   name = "username"   value = "root"   />
  16. < property   name = "password"   value = "ok" />
  17. </ bean >
  18. < bean   id = "sessionFactory"
  19. class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
  20. < property   name = "dataSource"   ref = "dataSource" />
  21. < property   name = "mappingResources" >
  22. < list >
  23. < value > org/springframework/lesson4/Person.hbm.xml </ value >
  24. </ list >
  25. </ property >
  26. < property   name = "hibernateProperties" >
  27. < props >
  28. < prop   key = "hibernate.dialect" >
  29. org.hibernate.dialect.MySQLDialect
  30. </ prop >
  31. </ props >
  32. </ property >
  33. </ bean >
  34. < bean   id = "dao"   class = "org.springframework.lesson4.PersonDAO" >
  35. < property   name = "sessionFactory"   ref = "sessionFactory"   />
  36. </ bean >
  37. < bean   id = "transactionManager"   class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
  38. < property   name = "sessionFactory"   ref = "sessionFactory"   />
  39. </ bean >
  40. < tx:advice   id = "txAdvice"   transaction-manager = "transactionManager" >
  41. < tx:attributes >
  42. < tx:method   name = "getAllPersons"   propagation = "REQUIRED" />
  43. </ tx:attributes >
  44. </ tx:advice >
  45. < aop:config >
  46. < aop:pointcut   id = "personPointer"   expression = "execution(* org.springframework.lesson4.IPersonDAO.*(..))" />
  47. < aop:advisor   advice-ref = "txAdvice"   pointcut-ref = "personPointer" />
  48. </ aop:config >
  49. </ beans >

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。