on 02-09-2015 5:55 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
Hi All,
I was trying to write AOP for classes available in web folder,followed the steps mentioned in below link.
But my aop is not being invoked,need to weave classes in platform HAC.
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Ben for your quick reply,But I Just wanted to ask, Can we add an aspect to a JALO or not. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ankit,
Have you configured load time weaving by adding the aspectj weaver jar to the JVM for startup?
Kind Regards,
Ben
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.