Reputation: 113
I am a beginner in Spring framework. I have implemented Spring AOP for logging method execution time. Using some examples from internet, I get it working for a Service interface as specified below. But the same code is not working if I change the expression to a non-service class. Have give below the CXF configuration.
<bean id="xbean" class="com........xServiceImpl" />
<jaxrs:server id="xServiceRS" address="/xRSService">
<jaxrs:serviceBeans>
<ref bean="xbean" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="performanceLoggingAdvice" class="com......PerformanceLoggingAdvice" />
<aop:config>
<aop:pointcut id="performanceLoggingPointcut"
expression="execution(* com.....xService.*(..))" />
<aop:advisor advice-ref="performanceLoggingAdvice"
pointcut-ref="performanceLoggingPointcut" id="performanceLoggingInterceptorAdvisor" />
</aop:config>
i have already searched in stack overflow for the similar question but I did not get a useful and specific answer to my question. Any idea what could be the issue ? How to get it working for a non service class for example Utils.java ?
Thanks in Advance for helping me..
Upvotes: 1
Views: 684
Reputation: 23812
The Spring AOP advices are only applied on the instances of the classes declared as Spring beans. Make your Util
class a Spring bean, use proper pointcuts and it should work.
You should obtain the Util
instances only through the Spring application context in that case (by calling one of the ApplicationContext.getBean
methods), not through a call to the constructor using new
.
Upvotes: 1