I am writing Spring 4 application with java config. I can use AOP in this project for all spring component. But i can't use it for a normal POJO class.
what is the library I need to add and what is the configuration I need to put in my config file to get this working
Spring AOP can only be applied to Spring-managed components/beans, not to non-Spring POJOs.
If you want to apply AOP to non-Spring classes you need AspectJ, not a proxy-based "AOP lite" framework like Spring AOP. For more information about how to use AspectJ (which does not need Spring at all) in combination with Spring and how to configure load-time weaving, please read the corresponding part of the Spring manual.
Related
Does Quarkus have a Spring AOP analogue? What could I use instead of Spring AOP on Quarkus?
Thank you!
Quarkus uses CDI as a dependency injection mechanism, CDI provides interceptors that can be use to implement the same functionalities as AOP provides.
What you need to do is define an annotation, annotate the method you want to intercept with this annotation then define an interceptor bind to this annotation.
This is described here: https://quarkus.io/guides/cdi#interceptors and you can find more information on interceptors here: https://docs.jboss.org/weld/reference/latest/en-US/html/interceptors.html
I have a question. Is it possible to inject spring bean into pure AspectJ project ( Let say we don't use Spring AOP, because of its limitations. We need to advice some static methods. )
And use those spring beans in AspectJ advices. Could we use CTW or LTW?
I am writing Spring 4 application with java config. I can use AOP in this project for all spring component. But i can't use it for a normal POJO class.
what is the library I need to add and what is the configuration I need to put in my config file to get this working
Spring AOP can only be applied to Spring-managed components/beans, not to non-Spring POJOs.
If you want to apply AOP to non-Spring classes you need AspectJ, not a proxy-based "AOP lite" framework like Spring AOP. For more information about how to use AspectJ (which does not need Spring at all) in combination with Spring and how to configure load-time weaving, please read the corresponding part of the Spring manual.
Difference between Spring AOP, AspectJ and Spring AOP with Annotation?
Here is my understanding:
Spring AOP means Springs Aspect oriented programming with xml based configurations.
AspectJ means its another AOP implementation which is not spring based, if we want to use it then we need to include some third party jars apart from spring.
Spring AOP annotation means spring uses AspectJ annotations to provide AOP feature.
are these fair assumptions?
Yes, that's right. Spring AOP have a limited options on AOP. The constructor and fields cant be intercepted with Spring AOP but it can be done using AspectJ.
Spring AOP also requires few AspectJ libries, like AspectJ weaving etc..
You can refer the link for more details.
Spring AOP vs AspectJ
Is it possible to configure spring AOP for a aspect around a method to either be turned on or off through a configuration properties file. The expression for the around is
execution(* com.company.service.update(..))
If you are using spring 3.1 or 3.2 you can use spring profiles to achieve this.
If you are using spring 4 you can use profiles or conditional declarations.