Spring AOP has a method-level tracer called CustomizableTraceInterceptor
. Using Spring's XML configuration approach, one would set up this tracer like so:
<bean id="customizableTraceInterceptor" class="
org.springframework.aop.interceptor.CustomizableTraceInterceptor">
<property name="enterMessage" value="Entering $[methodName]($[arguments])"/>
<property name="exitMessage" value="Leaving $[methodName](): $[returnValue]"/>
</bean>
<aop:config>
<aop:advisor advice-ref="customizableTraceInterceptor"
pointcut="execution(public * org.springframework.data.jpa.repository.JpaRepository+.*(..))"/>
</aop:config>
I would like to set up above configuration using Spring's JavaConfig style (i.e. taking advantage of Java annotations, especially @EnableAspectJAutoProxy
for activating AspectJ in JavaConfig).
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = { "some.package" })
@ComponentScan(basePackages = { "some.package2", "some.package3" })
@EnableAspectJAutoProxy
public class FacebookDomainConfiguration {
@Bean someBean() {
...
}
...
}
What is the @EnableAspectJAutoProxy
-style equivalent for <aop:advisor advice-ref="customizableTraceInterceptor" ...>
?
Just wanted to add to AdrienC's response. I'll use the point expression to reference an aggregated point, more clearer separation, imho
I do it this way :
Unfortunately, you cannot because the Java language does not support method literals which would be needed to support this in Spring JavaConfig. A bug was opened for this but marked as "Won't Fix": https://jira.springsource.org/browse/SPR-8148.
The two options mentioned in the bug report are:
<aop:config>
by including the relevant XML snippet using@ImportResource
<aop:config>
elemements to use@Aspect
style. [which is not possible with theCustomizableTraceInterceptor
]