JAVA-Spring AOP principles and notes manner

Principle of Spring AOP

    Spring user will get the object, generates a proxy for the target object, after the entry point in accordance with the rule, matching user connection point, to give a starting point, when the entry point is invoked, the target object does not go directly, but through a proxy object notice referred to the designated cut class to perform enhanced after interception.

    

    Spring automatically generating a proxy object for the target object is, by default, if the target object is achieved through an interface, java dynamic proxy mechanism is adopted, if the target object does not realized in the interface, using the default cglib dynamic proxy. Developers can be configured in the spring, it is required regardless of whether the target object is achieved through the interface are forced to use cglib dynamic proxy.

    

 

 

AOP annotations manner

    spring supports annotations manner AOP, with respect to the profile way, more lightweight configuration notes, configuration, modification more convenient, is the most popular way of it ~

    1. Open comments configuration of AOP

       

      2. The flag is a specified class section

        

    3. Configure notification entry point for the development of rules

      

      

      ** configuration through annotations equivalent to a configuration file

          

 

    

    4. If a cut in a plurality of notification pointcut reuse the same expression, you can define the pointcut expression alone, subsequent use, noted by annotation defined in the current section of only the current slice entry point play action, other facets not see.

       

    

 

    5 . In the post-notification annotations may be additionally arranged a returning attribute to specify a parameter name receives the return value of the method for performing the target

    

 

   6. Notes abnormal notification, you can also configure a throwing additional attribute, a parameter to specify the name of the target method receives the exception object thrown

    

 

Guess you like

Origin www.cnblogs.com/xiaoluohao/p/11286268.html