日期:2014-05-18 浏览次数:20774 次
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userManager' defined in class path resource [applicationContext-bean.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut allAddMethod
package com.bjsxt.spring; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; /** * 定义Aspect * @author Administrator * */ @Aspect public class SecurityHandler { /** * 定义Pointcut,Pointcut的名称就是allAddMethod,此方法不能有返回值和参数,该方法只是一个 * 标识 * * Pointcut的内容是一个表达式,描述那些对象的那些方法(订阅Joinpoint) */ @Pointcut("execution(* add*(..)) || execution(* del*(..))") private void allAddMethod(){}; /** * 定义Advice,标识在那个切入点何处织入此方法 */ @Before("allAddMethod()") private void checkSecurity() { System.out.println("----------checkSecurity()---------------"); } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <aop:aspectj-autoproxy></aop:aspectj-autoproxy> <bean id="securityHandler" class="com.bjsxt.spring.SecurityHandler"></bean> <bean id="userManager" class="com.bjsxt.spring.UserManagerImpl"></bean> </beans>