今日项目中用到Appfuse2.0作为框架,对这个框架做了些分析。
关于其他方面,就不多说了,网上资料比较全。但在分析AOP事务控制部分时,碰到一点小的疑惑:在applicationContext-service.xml中,advice配置如下:
<tx:advice id="txAdvice">
<tx:attributes>
<!-- Read-only commented out to make things easier for end-users -->
<!-- http://issues.appfuse.org/browse/APF-556 -->
<!--tx:method name="get*" read-only="true"/-->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
在 <tx:advice id="txAdvice">中,为什么没有transaction-manager属性啊(在1.9中还有的)?advice是怎么知道用哪个 transaction-manager来控制事务?
查了spring2.0 reference(http://static.springframework.org/spring/docs/2.0.x/reference/transaction.html)以后才明白:Tip: You can actually omit the 'transaction-manager' attribute in the transactional advice ( <tx:advice/>) if the bean name of the PlatformTransactionManager that you want to wire in has the name 'transactionManager'. If the PlatformTransactionManager bean that you want to wire in has any other name, then you have to be explicit and use the 'transaction-manager' attribute as in the example above.
原来 transaction-manager名称是 transactionManager(在applicationContext-dao.xml里面定义),在 <tx:advice id="txAdvice">中就省略不写了。也算是spring2.0的新“特性”吧。
个人认为这样虽然方便,但容易造成疑惑。就和autowire一样,省略的多了很可能带来理解上的困难。
特此备注。
AndyZ
关于其他方面,就不多说了,网上资料比较全。但在分析AOP事务控制部分时,碰到一点小的疑惑:在applicationContext-service.xml中,advice配置如下:
<tx:advice id="txAdvice">
<tx:attributes>
<!-- Read-only commented out to make things easier for end-users -->
<!-- http://issues.appfuse.org/browse/APF-556 -->
<!--tx:method name="get*" read-only="true"/-->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
在 <tx:advice id="txAdvice">中,为什么没有transaction-manager属性啊(在1.9中还有的)?advice是怎么知道用哪个 transaction-manager来控制事务?
查了spring2.0 reference(http://static.springframework.org/spring/docs/2.0.x/reference/transaction.html)以后才明白:Tip: You can actually omit the 'transaction-manager' attribute in the transactional advice ( <tx:advice/>) if the bean name of the PlatformTransactionManager that you want to wire in has the name 'transactionManager'. If the PlatformTransactionManager bean that you want to wire in has any other name, then you have to be explicit and use the 'transaction-manager' attribute as in the example above.
原来 transaction-manager名称是 transactionManager(在applicationContext-dao.xml里面定义),在 <tx:advice id="txAdvice">中就省略不写了。也算是spring2.0的新“特性”吧。
个人认为这样虽然方便,但容易造成疑惑。就和autowire一样,省略的多了很可能带来理解上的困难。
特此备注。
AndyZ