Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaConfig: Replacing aop:advisor and tx:advice
    text
    copied!<p>I'm wondering if I can map this piece of xml-configuration to Spring JavaConfig:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" default-autowire="byName"&gt; &lt;aop:config&gt; &lt;aop:pointcut id="serviceAnnotatedClass" expression="@within(org.springframework.stereotype.Service)" /&gt; &lt;aop:advisor id="managerTx" advice-ref="txAdvice" pointcut-ref="serviceAnnotatedClass" order="20" /&gt; &lt;/aop:config&gt; &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt; &lt;tx:attributes&gt; &lt;tx:method name="get*" read-only="true" /&gt; &lt;tx:method name="find*" read-only="true" /&gt; &lt;tx:method name="load*" read-only="true" /&gt; &lt;tx:method name="is*" read-only="true" /&gt; &lt;tx:method name="ownTransaction*" propagation="REQUIRES_NEW" rollback-for="Exception" /&gt; &lt;tx:method name="*" rollback-for="Exception" /&gt; &lt;/tx:attributes&gt; &lt;/tx:advice&gt; &lt;/beans&gt; </code></pre> <p>So far I figured out how to replace <strong>aop:pointcut</strong> with </p> <pre><code>&lt;aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="com.myapp.configuration.AspectConfig.serviceAnnotatedClass()" order="20"/&gt; </code></pre> <p>and</p> <pre><code>import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect public class AspectConfig { @Pointcut("@within(org.springframework.stereotype.Service)") public void serviceAnnotatedClass() {} } </code></pre> <p>Any hints how to replace the rest?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload