Java EE misc-how spring AOP is implemented

Source: Internet
Author: User

1. Traditional proxy mode.
  
  1. package springAOP;
  2. public class SubjectProxy implements IsubJect {
  3. private ISubject subject;
  4. public String Request(){
  5. //add pre-process logicif neccesary
  6. subject.request();
  7. //add post process if neccesary
  8. }
  9. public ISubject getSubject(){
  10. return subject;
  11. }
  12. public void setSubject(ISubject subject){
  13. this.subject=subject;
  14. }
  15. }

The disadvantage of this approach is to create a separate proxy class for each of the objects that are taken away from the object. It is a disaster when there are many functions that require proxies.
2. Dynamic proxies through the Java reflection mechanism are mainly implemented by the Java.lang.reflect.Proxy and Java.lang.reflect.InvocationHandler interfaces. Refer to other examples for details. The invoke function that the interface must implement can be seen as an advice of the AOP species
3. Dynamically generate bytecode via cglib. That is, using cglib to generate subclasses of the class to be proxied and then overwrite the corresponding method and insert the processing logic

Null

Java EE Miscellaneous-How spring AOP is implemented

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.