读书人

Spring3.0.5一部分命名空间

发布时间: 2012-09-03 09:48:39 作者: rapoo

Spring3.0.5部分命名空间

可叠加

Spring3.0.5一部分命名空间

当用户调用com.sarkuya.service包中任一类的任一方法,在调用前,Spring将自动执行下面的doBeforeInServiceLayer()方法,此方法只是简单地打印一些信息

上面的Aspect中混杂了Pointcut及Advice,可以将其分开

定义Pointcut,方法签名必须是public及void型

Beans

XSD:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

位置:org/springframework/beans/factory/xml/spring-beans-3.0.xsd

xmlns=”http://www.springframework.org/schema/beans”

默认Spring bean的声明

Spring3.0.5一部分命名空间2.??? <util:property-path/>元素

这里path=”helloworld.hello”就是指bean为”helloworld”的属性hello。

3.??? <util:properties/>元素

“classpath:”表明,将从类路径上查找并装载xxx属性文件.

4.??? <util:list/>元素
6.??? <util:set/>元素

<tx:jta-transaction-manager />???<tx:advice id=”txAdvice”>?????? <tx:attributes>?????????? <tx:method name=”plunder*” propagation=”REQUIRED” />?????????? <tx:method name=”*” propagation=”SUPPORTS” />?????? </tx:attributes>???</tx:advice>???<aop:config>?????? <aop:advisor pointcut=”execution(* ..Pirate.*(..))” advice-ref=”txAdvice” />???</aop:config>

<tx:jta-transaction-manager> 已经加入到 Spring2.5 中用于自动检测由 WebLogic , WebSphere 或 OC4J 提供的 JTA 事务管理。它默认是以叫“ transactionManager ”的 bean 配置在 Spring context 中的。

接下来, <tx:advice> 建立了一个 AOP advice 用于声明事务处理规则。在这个例子中,任何以“ plunder ”为前缀的方法都会得到一个事务。其它方法的规则则是“ support ”事务,并不要求一定会有事务来参与。最后,这个从先前 aop 命令空间借用的例子使用了具备事务性质的 advice 来配置成一个 AOP advistor 。定义在这儿的 pointcut 只对 Pirate 类的所有方法起作用。

Java 事务配置规则

如果你正在考虑压缩 Spring 配置的 XML 数据的话,考虑用 <tx:annotation-driven> 元素试试吧。一旦该元素配置好了,你可以使用开始使用 annotation 来配置你的 beans ,而且只要使用 @Transactional 来定义事务边界和规则即可。你可以看看 Spring In Action 2nd 第六章 6.4.4 节了解更多内容。

Mvc

XSD:http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

位置:org/springframework/web/servlet/config/spring-mvc-3.0.xsd

xmlns:mvc=”http://www.springframework.org/schema/mvc”

读书人网 >软件架构设计

热点推荐