Spring AOP and AspectJ

Source: Internet
Author: User
Tags aop
AspectJ

AspectJ is a very good AOP framework that extends the Java language and defines a set of SOP syntax. Therefore, Java projects that use AspectJ need to use the compiler AJC provided by AspectJ instead of Javac. AspectJ programming is available in two ways, using extended syntax or using annotations. 、

When using AspectJ alone in a Java project, projects that use MAVEN management need to rely on: Aspectjrt.jar provides the AspectJ runtime class library. Aspectjweaver.jar provides a dependency on the AspectJ annotation method. Aspectjtools.jar provides a compilation environment. Spring AOP

Because AspectJ is excellent, Spring AOP draws on the AspectJ project and provides partial support for AspectJ annotation-driven facets. Spring AOP's annotation syntax is exactly the same as AspectJ, but spring AOP supports only a subset of annotations. With spring AOP, there are two ways of configuring and slicing: XML and annotation declarations. You do not need to rely on AspectJ for any packages that use XML methods, and you need to rely on Aspectjweaver.jar when using annotations. Both of these methods use Javac as the compiler. Both of these methods only need to be compiled with Javac.

In addition, Spring provides proxy-based classic spring AOP and pure POJO facets, but because of their cumbersome syntax, AspectJ-based AOP support is provided in the new spring version, and the old way has been discarded. differences and linkages between Spring AOP and AspectJ Spring AOP, while syntactically referencing the annotated declaration of AspectJ, is still created and managed by the Spring IoC container in the implementation or spring-based dynamic proxy. In Spring AOP, slices are implanted at run time, which is the method of creating a dynamic proxy object that wraps the actual call. AspectJ is compiled with a compile-time implant, so it needs to be compiled using the compiler provided by AspectJ. In addition, AspectJ 5 also provides a way to implant the class during loading. When you use AspectJ alone, you can use the dependency injection method that Spring provides when you want to rely on member variables for facets.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.