Java AOP in Spring 2.0 Rob Harrop, Interface21 Ltd. Agenda • What's new in Spring 2.0 • Simplifying transaction configuration • @AspectJ Aspects • Writing pointcuts with AspectJ • Using AspectJ aspects • Aspects and JMX About the Speaker • VP at Interface21 • Core Developer on Spring • Founder of Spring Modules • JMX 2.0 Expert Group Member • Author of Pro Spring • Contact me at [email protected] What's new in Spring 2.0 • @AspectJ Aspects – Same syntax as AspectJ aspects – Use @AspectJ annotations and – Use the same aspect in Spring AJ – @AspectJ aspects are normal Spring beans • Inject dependencies into them • Configure them • Expose them to JMX or remote clients What's new in Spring 2.0 • Spring provides a model for true POJO Aspects – No annotations! What's new in Spring 2.0 • Simplified transaction configuration – TX-specific configuration tags • Define TX semantics with full code completion • Apply transactions using AJ pointcuts – Greatly simplified annotation-driven transactions • A single XML tag to enable! What's new in Spring 2.0 • Integrated AspectJ pointcut language – Single model for both Spring and AJ aspects – Reuse/share pointcuts in both environments – Greatly simplify Spring XML configuration • Paired with Spring 2.0 XML Simplifying transaction configuration • Option 1: XML only – Define TX advice using the <tx:advice/> – Apply advice using <aop:advisor/> Simplifying transaction configuration • <tx:advice id="txAdvice"> • <tx:attributes> • <tx:method name="*" • propagation="REQUIRED" • read-only="false"/> • </tx:attributes> • </tx:advice> • <aop:config> • <aop:advisor advice-ref="txAdvice" • pointcut="execution(* myapp.MyClass.*(..))"/> • </aop:config> Simplifying transaction configuration • Option 2: Using annotations – Add @Transactional to classes – Enable using <tx:annotation- driven/>
Description: