Search code examples
javaspringstruts2aopstruts2-spring-plugin

Advice is not called from struts 2 action?


Below i have define aspect in aop.xml

<aspects>
      <aspect name="com.customer.MyCustomAspect" />
 </aspects>

My Custom Aspect is define below

    @Aspect
    public class MyCustomAspect{
        @Around("@annotation(requiredPrivilege)")
            public Object myAdvice(ProceedingJoinPoint pjp) throws Throwable {

    }

Now when i call any service method from struts 2 action, myAdvice is not called. Every thing works fine with my legacy action but not with struts 2 action (Just for information i am using struts2 spring plugin jar). I am not what is the issue with struts 2?


Solution

  • Add the struts2-sping-plugin to your project.

    Add the following to struts.xml...

    <constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
    

    For more information see: http://struts.apache.org/release/2.0.x/docs/spring-plugin.html

    Since spring is now in charge of object creation it will now be able to perform it's spring AOP magic (assuming spring is configured correctly).