cancel
Showing results for 
Search instead for 
Did you mean: 

AOP in hybris not working

Former Member
0 Kudos

Hi , I am working on a simple AOP functionality , where I want my advice to be called before the excution of the de.hybris.platform.cronjob.jalo.CronJob.sendEmail(). But my aspect is not even called when I used annotation based configuration. I had just made my aspect's bean entry in myextention-spring.xml and bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator".Created an aspect for that as well. My standalone sample AOP app is working perfectly. Is there any thing I am doing wrong.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Ankit,

Some steps that I can suggest:

  • In your extension add to the resources folder a folder called META-INF and place aop.xml here.

  • Create a class to act as your aspect in the src - {Pakage - path}.YourAspect.java

  • In this class you need to decorate it with the @Aspect annotation and use a pointcut to in your case the Cronjob.sendEmail method. This would like something like the following:

@Pointcut("execution(* de.hybris.platform.cronjob.jalo.CronJob.sendEmail(..))") public void theExample() { //Leave empty }

You also add your advice here which references this pointcut:

//Example with Around advice

@Around("theExample()") public Object theMethod(final ProceedingJoinPoint pjp) { //Your logic log.info("ASPECT INVOKED");

Object o = pjp.proceed; /Don't forget in an around advice to to call the jointpoints proceed/ return o;

  • Within the aop.xml are located your weaves. So it would be something like:

 <aspectj>
     <weaver options="-Xset:weaveJavaxPackages=true">
         <include within="com.yourpackage.aspects.." />
         <include within="de.hybris.platform.cronjob.jalo.." />
     </weaver>
     <aspects>
         <aspect name="com.yourpackage.aspects.YourAspect" />
     </aspects>
 </aspectj>

You will experience performance problems if you weave the entire platform. i.e.Just include your package and the cronjob package in the include within. The .. includes subfolders while the * acts as a wildcard.

Now if you've added the aspect jar as an argument to the VM on startup these classes should be weaved through load time weaving.

I hope this information proves useful to you.

Best Regards,

Ben

Former Member
0 Kudos

Hi Ben,

This is the best solution i have ever received for any problem.

Thanks

Former Member
0 Kudos

Hi Ankit,

You're very welcome. I'm happy it has helped you.

Best Regards,

Ben

Former Member
0 Kudos

Thanks for solution. It worked for me in 6.0 and I did not had to use aop.xml. Used only annotations. Now wanted to check if I have to pointcut on all overriden perform() method of all the extended cronjobs like mycronjob1.perform() , mycronjob2perform() , how should I define the pointcut in one single annotation. Is this possible ? If not do I have to define multiple methods for each extended cronjob class?

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi All,

I was trying to write AOP for classes available in web folder,followed the steps mentioned in below link.

https://help.hybris.com/6.0.0/hcd/8c62d88286691014874bc5b8e7244c7a.html#loio8c62d88286691014874bc5b8...

But my aop is not being invoked,need to weave classes in platform HAC.

Regards,

Former Member
0 Kudos

Hi ANKIT,

I think the Ben solution will work without any problem.

But just I have a little doubt about your bean configuration. Spring by default has enabled two types of aop one is JDK and another one is CGLIB both are integrated in the core so you do not need to add external libraries to the app. But by default ( if you do not specify it spring will use the JDK ) that it will not work in several case : 1. the class with the method that you want apply the advice does not implement an interface ( your case ) 2. if the method it is not public.

If you want to tell spring to use the CGLIB you should set proxy-by-class=true in aop config tag ( if you used the xml configuration ).

check this out : http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop-api.html#aop-pfb-proxy...

Former Member
0 Kudos

Hi Segio,

Spring by default take care of this. If your target class is not implementing any interface it will use CGLIB AOP.

Thanks

Former Member
0 Kudos

That is possible based on the information that Ben provided. It is not possible to annotate this in Spring because spring does not know about jalo classes but instead you add those aspects when a class is loaded. I have used this technique and it works fine. Read the documentation ones mores :)

Former Member
0 Kudos

Thanks Ben for your quick reply,But I Just wanted to ask, Can we add an aspect to a JALO or not. Thanks

Former Member
0 Kudos

Hi Ankit,

Have you configured load time weaving by adding the aspectj weaver jar to the JVM for startup?

https://wiki.hybris.com/display/release5/Spring+AOP+in+the+hybris+Commerce+Suite#SpringAOPinthehybri...

Kind Regards,

Ben