Spring自定义切面采用两种方式:一是使用xlm配置,二是使用注释。在3.0以后使用spring注释时一定要注意,配置方式已经改变。
一,spring3.0以前注释使用方式如下:
@Aspect
public class CheckUser {
@Pointcut("execution(* org.service.*.find*(..))")
public void checkUser() {
System.out
.println("**************The System is Searching Information For You****************");
}
@Pointcut("execution(* org.service.*.add*(..))")
public void checkAdd() {
System.out.println("**************<< Add User >> Checking.....***************");
}
@Before("checkUser()")
public void beforeCheck() {
System.out.println(">>>>>>>> 准备搜查用户..........");
}
@After("checkUser()")
public void afterCheck() {
System.out.println(">>>>>>>> 搜查用户完毕..........");
}
@Before("checkAdd()")
public void beforeAdd() {
System.out.println(">>>>>>>> 增加用户--检查ing..........");
}
@After("checkAdd()")
public void afterAdd() {
System.out.println(">>>>>>>> 增加用户--检查完毕!未发现异常!..........");
}
}
一,spring3.0以后注释使用方式如下:
@Aspect
public class CheckUser {
/*
* @Pointcut("execution(* com.jushi.aop.*.find*(..))") public void
* checkUser() { System.out .println(
* "**************The System is Searching Information For You****************"
* ); }
*
* @Pointcut("execution(* com.jushi.aop.*.add*(..))") public void checkAdd()
* { System.out
* .println("**************<< Add User >> Checking.....***************"); }
*/
@Before("execution(* com.jushi.aop.*.add*(..))")
public void beforeCheck(JoinPoint jp) {
System.out.println(">>>>>>>> 准备搜查用户..........");
}
@After("execution(* com.jushi.aop.*.add*(..))")
public void afterCheck(JoinPoint jp) {
System.out.println(">>>>>>>> 搜查用户完毕..........");
}
@Before("execution(* com.jushi.aop.*.add*(..))")
public void beforeAdd(JoinPoint jp) {
System.out.println(">>>>>>>> 增加用户--检查ing..........");
}
@After("execution(* com.jushi.aop.*.add*(..))")
public void afterAdd(JoinPoint jp) {
System.out.println(">>>>>>>> 增加用户--检查完毕!未发现异常!..........");
}
}
如果使用不当会出现
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'user' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut checkAdd
Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut checkAdd
分享到:
相关推荐
NULL 博文链接:https://lijunabc.iteye.com/blog/641277
本书主要介绍了Spring 3.0的核心内容,不仅讲解了Spring 3.0的基础知识,还深入讨论了Spring IoC容器、Spring AOP、使用Spring JDBC访问数据库、集成Hibernate、Spring的事务管理、Spring MVC、单元测试、敏捷开发...
开发spring AOP功能时所需要的额外jar包,外加上spring3.0以上官方给出的jar包即可
使用Spring配置文件实现AOP
Spring基础:Spring AOP简单使用
spring-aop-3.0.xsd
Spring3.0.5支持AOP获取HttpServletResponse扩展资源:spring.web-3.0.5.jar和spring.webmvc-3.0.5.jar 是需要升级替换的。
spring-aop-3.0.xsd 这个下载之后可以直接放在eclipese的xml的catalog中配置,已到达eclipse可以自动提示xml的功能
spring-aop-1.1.1.jar spring-aop-1.2.6.jar spring-aop-1.2.9.jar spring-aop-2.0.2.jar spring-aop-2.0.6.jar spring-aop-2.0.7.jar spring-aop-2.0.8.jar spring-aop-2.0.jar spring-aop-2.5.1.jar spring-aop-...
Spring3.0学习文档主要讲解的是IOC和AOP 静态代理、动态代理这些内容是Spring3.0中最难理解的重点知识点
Spring3.1 IOC+AOP需要的jar包 ,实践检验过,亲身实践的
spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop spring aop
NULL 博文链接:https://phl.iteye.com/blog/871022
使用Spring的注解方式实现AOP的细节
开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE开发工具 spring-aop-4.3.6.RELEASE...
源代码是spring-boot添加aop切面功能的demo,简单易懂.