In some cases, the JDK used in our engineering is not necessarily more than 1.5, which means that annotation annotations may not be supported by nature, and it is not possible to use @aspectj annotation-driven AOP, so if we still want to use AspectJ flexible pointcut expressions, So what should we do? Spring provides us with an AOP namespace based on XML schemati
= (braveknight) Ac.getbean ("Knight"); - br.saying (); - } -}Operation Result:annotation type Wrapping Notification: Surround FrontNote Type pre-notificationI'm a knight. (Tangent method)annotation type Wrapping Notification: After wrappingNote Type post-placement notification======================== Split Line ===================================Because of the use of annotations, so the configuration file a lot less content, only need a sentence context:component-scan base-package= "Com.cjh
Today, I looked at the video of the Dark Horse programmer, a small example of using spring AOP + custom annotations to implement permission control, personally feel that can be used for reference, organized out to share with you.Requirements: The service tier has methods that require different permissions to access.Implementation: Customize a privilegeinfo annota
This example uses the previous Spring-spring mvc Framework getting started. Of course, you can also use your own.
1. Because @ Aspect is used to mark this class as a class for setting attention (partition class...), a corresponding jar file is required. The corresponding file in my resources, the name is called aspectj-1.7.0.jar, the compressed package contains a
be accessed in the notification body in the following sections.
ImplementedAccountserviceAny connection point of the target object of the interface (only method execution in Spring AOP ):Target (COM. XYZ. Service. accountservice)'Target' is used in binding form:-see the following section on how to make the target object accessible in the notification body.
Each parameter accepts only one parameter and
Spring boot aop record method execution time code example, springaop
This article focuses on the implementation code of spring boot aop recording method execution time, as follows.
In order to optimize the performance, we need to calculate the execution time of each method f
()); */}}Execution Result:Entry Method ---Surround notifications>>>>>>>> ready to search users ..........---------------" FindAll ": {smith=smith00, tom=tom00, xiaoming = Xiao Ming xx, lucy=lucy00,hello=hello00}------------------Exit Method ---Surround notifications>>>>>>>> Search User Complete ..........Note: @Before is to execute a piece of logic before the intercepted method executes. @After is to execute a piece of logic after the intercepted method executes. @Around is a logic that can be
Specific cases on GitHub, mostly jar packages on topHttps://github.com/guoyansi/spring-aop-exampleKnights.xmlXML version= "1.0" encoding= "UTF-8"?>Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.o
Brief introductionaspect-oriented programming (AOP) provides another way to think about the structure of a program, making up for the lack of object-oriented programming (OOP). In addition to classes (classes), AOP provides slices. Cut to the point of concern for modularity, such as transaction management across multiple types and objects. (These attention-point terms are often referred to as crosscutting (
Because the most recent service item provides an interface with a requirement, all operations must check that the operation of the service is available, so the sense that AOP is particularly suitable for implementation. A small example of completing a study.About SPRING-AOP principle: http://m.oschina.net/blog/174838 T
Transaction management under Spring-using AOP XML configuration management (IBatis as an example)
There are three ways to manage things under Spring: programmatic transaction management, declarative transaction management, and AOP transaction management.
Main Source: http://howtodoinjava.com/spring/spring-aop/writing-spring-aop-aspectj-pointcut-expressions-with-examples/1. Method Label Matching modeAssume that the interface Employeemanager interface is defined.1)Execution (* com.howtodoinjava.employeemanager.* (..))The above
" Expression="Org.aspectj.lang.annotation.Aspect"/> context:component-scan> -- aop:aspectj-autoproxy/> Beans>Test
public class beantest {Public static void main (string[] args){ //Create a spring container ApplicationContext ctx = new Classpathxmlapplicationcontext ("Beans.xml");Hello hello = ctx.getbean ("Hello" , hello. Class);Hello.foo ();Hello.adduser ("Goku", "7788");//Throws an exception--the length of the name is not enoughWorld W
After this period of study and use of spring, slowly realize the excellent spring, is deeply absorbing the essence of spring, hehe. This is just a simple AOP example, including a pre-notification, a post-notification, a surround notification, and a target object. The main go
Project structure, the basic spring configuration is not to repeat1. First write your custom slice classPackage org.wu.test;Import org.aspectj.lang.annotation.AfterReturning;Import Org.aspectj.lang.annotation.Aspect;Import Org.aspectj.lang.annotation.Before;Import Org.aspectj.lang.annotation.Pointcut;Import org.springframework.stereotype.Component;@Component@Aspectpublic class DIv {@Pointcut ("Execution (* Org.wu.test.WyzController.say (..))")public v
) public void afterThrowing(JoinPoint jp, Throwable ex) { System.out.println(error is: + ex); }There's no exception here, there's no output.The test code is as follows@Configuration@EnableAspectJAutoProxy@ComponentScan(basePackages = com.ydoing.service,com.ydoing.aspect)public class AppConfig { public static void main(String[] args) { @SuppressWarnings(resource) ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); SimpleService s
Cn.itcast.service.PersonService;
public class Personservicebean implements Personservice {Public String getpersonname (Integer PersonID) {SYSTEM.OUT.PRINTLN ("------This is the Getpersonname method");return "XXX";}
public void Save (String name) {throw new RuntimeException ("I love the Exception");SYSTEM.OUT.PRINTLN ("------This is the Save Method");}
public void Update (String name, Integer PersonID) {SYSTEM.OUT.PRINTLN ("------This is the Update method");}
}
---------------------------------
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.