chapter can be skipped.6.1.1. AOP ConceptsFirst let's start with some important AOP concepts and terminology. These terms are not unique to spring. But AOP terminology is not particularly intuitive, and if spring uses its own terminology, it will become even more confusing.
framework
Provides declarative enterprise services, especially in lieu of EJB declarative services. The most important service is Declarative transaction management (which I think is the most common use of AOP).
Allows users to implement custom facets, using AOP to refine the use of OOP.
1.AOP Concept:To learn
transaction logic, with AOP, it can focus only on what you want to do (AOP allows him to do what he wants to do with sex)7. proxy)The object of the Application Notification. For details, see the proxy mode in the design mode.8. Weaving)The process of applying a cut surface to a target object to create a new proxy object is usually as follows:(1) Compile time: When a class file is compiled, it is woven into
Spring AOP-configuration based on XML files, aop-xml
The configuration of Spring AOP can be based on Annotations or XML files. The previous articles use annotations. The following describes how to configure an XML file.
The used test class and cut class are similar. You only
the horizontal multi-module unified control of program functions through precompilation and run-time dynamic agent. AOP is a complement to OOP and an important part of the spring framework. AOP enables the isolation of parts of the business logic, which reduces the coupling between parts of the business logic, improves the reusability of the program, and improve
, which encapsulates the common behavior of multiple classes into reusable modules, The module contains a set of APIs that provide crosscutting functionality. For example, a log module can be called an AOP facet of a log. Depending on the requirements, an application can have several facets. In SPRINGAOP, facets are implemented by classes with @aspect annotations.
connection point (joinpoint): An explici
. Transaction management is a good example of a crosscutting concern in the Java EE application. In spring AOP, facets can be implemented using generic classes (pattern-based styles) or @Aspect annotations (@AspectJ styles) in ordinary classes.
Connection point (Joinpoint): a particular point in the execution of a program, such as when a method is called or whe
");//Can find Zhang San Usermanager.finduserbyid (1); System.out.println ("===== i = = = = Division = = Cut = = Line ====="); try {//Cannot find the data, will throw an exception, Exceptions are captured by Afterthrowingadvice Usermanager.finduserbyid (0);} catch (IllegalArgumentException e) {}}}Run Results Normal operation, no exception thrown (i) abnormal operation, with exception thrown (ii)The purpose of the above two graphs is to give you a clearer picture of the advice five types of runn
Insert a system service (such as Logging and Security) unrelated to the business logic in a service process. This logic is called Cross-cutting concerns, the Cross-cutting concerns is designed as an object. This special object is called Aspect ), aspect-oriented programming focuses on Aspect design and Weave ).
AOP and OOP do not conflict with each other. They are two complementary design models. Spring
also used this AOP idea: Using dynamic Proxy technology to add this extracted handler to all the service to form proxy objects.There is also an example of an interceptor, which also uses the idea of AOP:2. Why Learning AOPEnhance the program: without modifying the source code
AOP can perform permissions check
just a programmatic
Spring allows you to customize transactional behavior through AOP. For example, if you want, you can insert custom behavior in a transaction rollback. You can also add any notice, just like a transaction notice. With EJB CMT, you have no way to affect the transaction management of a container other than using setrollbackonly ()
interception method object[] arguments=Joinpoint.getargs (); An array of parameter objects that get the Intercept method ClassClass.forName (targetName); Class method[] Methods for intercepted objects=Targetclass.getmethods (); Get all the methods for intercepting objects String description= ""; for(method Method:methods) {//Traversal methodif(Method.getname (). Equals (MethodName)) {//when the name of this method is the same as the name of the interception method class[] Clazzs=method.getpara
Spring3.x tutorial (2) Spring AOPI. Introduction to Spring AOPIn fact, development is constantly refactoring, abstracting and repeating code, and then encapsulating it. From the most primitive Modular programming to object-oriented programming, code encapsulation becomes more and more neat and clear, but there are still repeated code, which are almost all system logic code unrelated to the business logic. F
propertyplaceholderconfigurer load in spring, and database connection information, The Jndi connection information properties file can also be managed by propertyplaceholderconfigurer loading into spring. Usage is as follows:(1). Load additional files into spring by Propertyplaceholderconfigurer:Add the following configuration in the
method, or an exception thrown. In Spring AOP, a connection point is always a call to a method☞ Enhanced Processing (Advice): The enhanced processing that an AOP framework performs at a specific pointcut. The processing has "around", "before" and "after" type☞ pointcut (Pointcut): A connection point in which enhanced processing can be inserted. In short, when a
not play his powerful role, of course , if there is no spring aop,ioc there are still a lot of problems can not be solved, at the same time, we are thinking about the other spring technology, such as transactions, we should be more clear about the transaction, spring's transaction is to be AOP into
Dependency injection and AOP programming in Spring developed by JavaEE, javaeeaop
In the previous blog, we talked about how to build an Eclipse-based environment for Java EE development and how to create a Maven Web App. In the previous blog, we talked about dependency injection, in addition, Objective-C Runtime is used to implement dependency injection in ObjC. For related blogs, refer to "Implementing dep
Original source: ListenAOP (Aspect Orient programming), which we generally call aspect-oriented programming, complements the object-oriented approach to the crosscutting concerns that are distributed across modules in the system, such as transaction management, logging, caching, and so on. The key to the AOP implementation is the AOP proxy, which is automatically created by the
ASPECTJ because it supports compile-time weaving and does not require a build agent.Bearkidult translated more than 3 years ago2 person TopTopWell translated! You will want to use an easy-to-implement approach. Because spring AOP supports annotations, it is more convenient to use @aspect annotation creation and configuration. With ASPECTJ, you need to create the facet through the. aj file, and you need to
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.