Spring finishing 2

Source: Internet
Author: User
1. what is AOP Aspect-Oriented aspect programming? Unlike Oop, oop focuses on class and encapsulation. important Aspect functions of AOP. AOP is a supplement to OOP, improving and improving the program structure. the role of AOP in Spring framework is as follows: 1) declarative transaction management; 2) custom aspect. Use AOP to improve the use of OOP. The AOP proxy in spring is generated and managed by the IOC container, and the dependency pages between components are managed by the IOC container. So the goal of AOP can be the bean in the IOC container. 2. AOP-related concepts 1) aspect can be used in common, and multiple target objects or methods can be used, also known as concerns. 2) A set of pointcut matching connection points. specify a batch of connection points in expression mode. 3) specify a specific point during program execution, such as when a method is called or an exception is handled. 4) the time when the notification (advice) plane method executes the action at the connection point. for example, before a method call, after a method call, before and after a method call, after an exception occurs, etc. 5) target object 6) AOP proxy spring container dynamically creates an object, this proxy object can call the cut method and the target object method. in spring, the AOP proxy can be JDK dynamic proxy or cglib proxy. 3. notification 1) pre-notification: Before advice executes the cut surface method before calling the target object method 2) Post-Notification: After returning advice executes the cut surface method after calling the target object method, (the target method does not have any exceptions.) 3) final notification: After (finally) Advice executes the cut-plane method after calling the target object method (the target method can be used if there are any exceptions) 4) surround notification: Around advice executes the aspect processing before calling the target object method. 5) exception notification: After throwing advice encounters an exception when calling the target method, run the cut surface method try {// pre-notification // pre-processing of the surround notification // call the Business Method of the target object // post-processing of the surround notification // post-Notification} catch (exception E) {// exception notification} finally {// final notification} 4. entry Point expression * 1) execution-limit the connection for matching method execution Click execution (modifiers-pattern? Ret-type-pattern declaring-type-pattern? Name-pattern (param-pattern) throws-pattern ?) Example 1. match arbitrary public method execution (Public **(..)) example 2. match the execution (* Set * (...) of any method whose name starts with "set *(..)) example 3. arbitrary method execution (* COM. XYZ. service. accountservice. *(..)) example 4. match any execution (* COM. XYZ. service. *. *(..)) example 5. matches any execution (* COM. XYZ. service .. *. *(..)) * 2) within-specify one or more types of connection points. Example 1. match all types of methods in the service package within (COM. XYZ. service. *) Example 2. match all types of methods in the service package and sub-package within (COM. XYZ. service .. *) Example 3. match any method in accountservice within (COM. XYZ. service. accountservice) 3) This-specifies a connection point that matches a proxy type. Example 1. match any connection point of the proxy object that implements the accountservice interface this (COM. XYZ. service. accountservice) 4) Target-specify a connection point that matches a target object type. Example 1. match any connection point of the target object implementing the accountservice interface target (COM. XYZ. service. accountservice) 5) ARGs-Example of a method parameter that limits matching a connection point 1. the matching method has only one parameter and is The args of serializable (Java. io. serializable) * 6) bean-Example 1. example 2 of an object Bean (personservice) that matches the bean element ID with the name "personservice. match the bean element ID "* service" Object Bean (* Service) 5. use of AOP annotation 1) enable the annotation parser in xml configuration <AOP: aspectj-autoproxy/> 2) the AOP annotation that can be used in the aspect bean @ aspect: specify the bean component as a cut component @ pointcut: Specify the entry point expression @ before: pre-notification @ afterreturning: post notification @ After: final notification @ around: surround notification @ afterthrowing: exception notification

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.