cancel
Showing results for 
Search instead for 
Did you mean: 

Add aspect in storefront Controller?

Former Member
0 Kudos

How can create aspect for annotated methods (with my own annotation) in @Controller class? I've tried by spring-mvc-config.xml or adding aop.xml as is said here: https://wiki.hybris.com/display/release5/Spring+AOP+in+the+hybris+Commerce+Suite. Furthermore the second way works fine in core module or even in for example *Filter classes in storefront module.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I have the same problem, and for some reason I cannot use aspectj annotated classes directly. So instead of annotating the aspect with @Aspect and @Around annotations, I simply configured the aspect behavior in the -spring.xml file of my extension (not the storefront one):

 <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:context="http://www.springframework.org/schema/context"
        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/context
            http://www.springframework.org/schema/context/spring-context.xsd">;
 
     <context:annotation-config/>
     <context:component-scan base-package="com.mypackage" />
 
     <aop:config proxy-target-class="true" expose-proxy="true">
         <aop:aspect id="myAdviseAspect" ref="myAspect">
             <aop:around method="advise"
                         pointcut="execution(* *(..)) &amp;&amp; @annotation(annotation)"/>
         </aop:aspect>
     </aop:config>
 
     <bean name="myAspect" class="com.mypackage.MyAspect"/>
 </beans>

Then I simply declared the method "advise" like this:

 public Object advise(final ProceedingJoinPoint joinPoint, MyAnnotation annotation) throws Throwable {
     ...
 }