Discover aspect oriented programming spring, include the articles, news, trends, analysis and practical advice about aspect oriented programming spring on alibabacloud.com
Implement AOP programming using spring annotations and XMLTo implement the AOP programming annotation method, follow these steps:
1) Introduce jar files related to aop first (excellent aspectj aop components)
Spring-aop-3.2.5.RELEASE.jar [spring3.2 source code]
Aopalliance. jar [spring2.5 source code/lib/aopalliance]
A
Prerequisites :Import the jar required for AOP:Aspectjweaver.jar and Aspectjrt.jar and Cglib-nodep-2.1_3.jarnamespaces required for joining AOP:xmlns:aop="http://www.springframework.org/schema/aop" http:// WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-2.5.xsdSpring provides two ways to use facets:Based on annotation and XML-based methods.development of AOP based on annotations :Premise:Precede with an AO
AOP is the Aspect oriented program for slicing. In the AOP thought, the function is divided into the core business function and the periphery function.The so-called core business, such as landing, adding data, deleting data is called the core business.The so-called peripheral functions, such as performance statistics, logging, transaction management and so on.The perimeter function is defined as a slice in
AOP- oriented tangent programming in the daily development, the business logic is defined under a special service package, and the implementation is defined in the impl package under the service package.Service Interfaces to Ixxxservice form, and service realization is xxxservice, this is the protocol designsteps:1.e:\users\workspaces\kmwalletapp\spring\aop\test
First, Introduction:The ASPECTJ framework not only implements aspect-oriented programming, but also supports annotations, which spring introduces into its own specifications.Second, need to understand:
ASPECTJ is an AOP framework based on the Java language
Support for ASPECTJ pointcut expressions after spring2
First, it should be understood that AOP is a programming paradigm and a programming idea that is not related to specific computer programming languages, so it is not just Java, but other programming languages like. NET have AOP implementations. The idea of AOP is to separate the general logic from the business logic.Th
First defineA slice class@Aspect @componentUse the above annotations to indicate that the class is a slice classAnd customize two methods in the Slice class, respectively, after executing thepublic void before (Joinpoint jp) { ... } public void after (Joinpoint jp) { ... }Inject the class in the spring configuration fileThen configure the slice program with AOPSlice interception Handle
What exactly is AOP?
AOP is the abbreviation of Aspect oriented programming, meaning: face-oriented programming (also called aspect-oriented), through the precompilation and runtime dy
Org.aspectj.lang.annotation.pointcut;import org.springframework.stereotype.Component; @Component @aspect// The slice class public class Log {/*** * Configures the pointcut, which has no method body */@Pointcut ("Execution (* com.yuan.service).ad* (..)) ")public void Daddff () {}; /*** * Configure the Pre-notification * @param joinpoint */@Before ("DADDFF ()") public void before () {System.out.println ("Add Day"); }} 1.5 Configuration file Bean.xml 1.
AOP-oriented tangent programmingAOP allows for complete separation of "business code" and "Focus Code" @Override public list Analysis:The focus code refers to the code that executes repeatedly.Business code and attention Point code separation, benefits?--Focus code write once.-developers need to focus on their core business--During operation, the dynamic implantation of the focus code when executing the business code; (Proxy implementation)How to
1: Create a common Bean:role attribute id,name, add the parameterless construct, setter getter method2: Create a new interface: RoleService, write a method printrole3: Create a new class Roleserviceimpl, implement the RoleService interface, override the Printrole methodNotice @Component note, don't forget.4: Define slice class Roleaspect add four notification methodsNote: Add @aspect annotationsThe parameters in execution must be written in pairs, exa
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.