spring1.1和2.0中aop建议配置

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.        
  13.      < bean   id = "dataSource"   class = "org.apache.commons.dbcp.BasicDataSource" >   
  14.          < property   name = "driverClassName"   value = "com.mysql.jdbc.Driver" />   
  15.          < property   name = "url"   value = "jdbc:mysql://localhost:3306/eimhe" />   
  16.          < property   name = "username"   value = "root"   />   
  17.          < property   name = "password"   value = "ok" />   
  18.      </ bean >   
  19.        
  20.      < bean   id = "sessionFactory"   
  21.          class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >   
  22.          < property   name = "dataSource"   ref = "dataSource" />   
  23.          < property   name = "mappingResources" >   
  24.              < list >   
  25.                  < value > org/springframework/lesson4/Person.hbm.xml </ value >   
  26.              </ list >   
  27.          </ property >   
  28.          < property   name = "hibernateProperties" >   
  29.              < props >   
  30.                  < prop   key = "hibernate.dialect" >   
  31.                     org.hibernate.dialect.MySQLDialect   
  32.                  </ prop >                   
  33.              </ props >   
  34.          </ property >   
  35.      </ bean >   
  36.        
  37.      < bean   id = "dao"   class = "org.springframework.lesson4.PersonDAO" >   
  38.          < property   name = "sessionFactory"   ref = "sessionFactory"   />   
  39.      </ bean >   
  40.        
  41.      < bean   id = "transactionManager"   class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >   
  42.          < property   name = "sessionFactory"   ref = "sessionFactory"   />   
  43.      </ bean >   
  44.        
  45.      < bean   id = "personProxy"   class = "org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >   
  46.          < property   name = "transactionManager"   ref = "transactionManager" />   
  47.          < property   name = "proxyInterfaces" >   
  48.              < list >   
  49.                  < value > org.springframework.lesson4.IPersonDAO </ value >   
  50.              </ list >   
  51.          </ property >   
  52.          < property   name = "target"   ref = "dao"   />   
  53.          < property   name = "transactionAttributes" >   
  54.              < props >   
  55.                  < prop   key = "getAll*" > PROPAGATION_REQUIRED </ prop >   
  56.              </ props >   
  57.          </ property >   
  58.      </ bean >   
  59. </ 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.        
  13.      < bean   id = "dataSource"   class = "org.apache.commons.dbcp.BasicDataSource" >   
  14.          < property   name = "driverClassName"   value = "com.mysql.jdbc.Driver" />   
  15.          < property   name = "url"   value = "jdbc:mysql://localhost:3306/eimhe" />   
  16.          < property   name = "username"   value = "root"   />   
  17.          < property   name = "password"   value = "ok" />   
  18.      </ bean >   
  19.        
  20.      < bean   id = "sessionFactory"   
  21.          class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >   
  22.          < property   name = "dataSource"   ref = "dataSource" />   
  23.          < property   name = "mappingResources" >   
  24.              < list >   
  25.                  < value > org/springframework/lesson4/Person.hbm.xml </ value >   
  26.              </ list >   
  27.          </ property >   
  28.          < property   name = "hibernateProperties" >   
  29.              < props >   
  30.                  < prop   key = "hibernate.dialect" >   
  31.                     org.hibernate.dialect.MySQLDialect   
  32.                  </ prop >                   
  33.              </ props >   
  34.          </ property >   
  35.      </ bean >   
  36.        
  37.      < bean   id = "dao"   class = "org.springframework.lesson4.PersonDAO" >   
  38.          < property   name = "sessionFactory"   ref = "sessionFactory"   />   
  39.      </ bean >   
  40.        
  41.      < bean   id = "transactionManager"   class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >   
  42.          < property   name = "sessionFactory"   ref = "sessionFactory"   />   
  43.      </ bean >   
  44.        
  45.      < tx:advice   id = "txAdvice"   transaction-manager = "transactionManager" >   
  46.          < tx:attributes >   
  47.              < tx:method   name = "getAllPersons"   propagation = "REQUIRED" />   
  48.          </ tx:attributes >   
  49.      </ tx:advice >   
  50.        
  51.      < aop:config >   
  52.          < aop:pointcut   id = "personPointer"   expression = "execution(* org.springframework.lesson4.IPersonDAO.*(..))" />   
  53.          < aop:advisor   advice-ref = "txAdvice"   pointcut-ref = "personPointer" />   
  54.      </ aop:config >   
  55. </ beans >  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值