引入AOP 报错 error at ::0 formal unbound in pointcut

使用了AOP 后启动报错

九月 27, 2016 2:29:46 下午 org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘acAction‘: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘accountService‘ defined in file [D:\workspace_eclipse_mars\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bpmp\WEB-INF\classes\com\bkc\bpmp\xdj\zc\service\impl\AccountServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
九月 27, 2016 2:29:46 下午 org.springframework.web.servlet.FrameworkServlet initServletBean
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘acAction‘: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘accountService‘ defined in file [D:\workspace_eclipse_mars\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\bpmp\WEB-INF\classes\com\bkc\bpmp\xdj\zc\service\impl\AccountServiceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)

  

在使用声明方式的AOP编程中,遇到以下问题,解决方法如下:

(1)error at ::0 formal unbound in pointcut

解决方法:去掉函数通知函数中的参数,比如:将

@Before("execution(public void com.bjsxt.dao.impl.UserDAOImpl.*(..))")

public void beforeMethod(Method method){

System.out.println("method before");

}

改为

@Before("execution(public void com.bjsxt.dao.impl.UserDAOImpl.*(..))")

public void beforeMethod(){

System.out.println("method before");

}

情况二:

原写法:

@Before("@annotation(org.haha.web.annotation.BrowAuth)
public void beforeExec(HttpServletRequest request) {

......

}

会报以下错误:

0 formal unbound in pointcut

原因是应该用args指明参数,改成以下就可以了:

@Before("@annotation(org.haha.web.annotation.BrowAuth) && (args(request,..) || args(..,request))")
public void beforeExec(HttpServletRequest request) {

......

}

方法中未带参数,本bug 非此原因

(2)可能原因(我的猜测,未确认)

  使用了AOP 之后(spring),实现注解是采用代理的方式,而代理有两种jdk自带代理和 cglib,而在springmvc 中直接使用自动注解的时候,没有使用这一层代理。接口、接口的实现类,其注解的命名方式不一致,造成了自动注入的时候,代理不知道该选择哪一个类……

  可解决方法:一、使用AOP注解,将原有的业务上的接口、接口实现类的命名改统一。假设接口为 IUserDao,实现类为 UserDaoImpl ,自动注入的时候写成  IUserDao userDaoImpl  (原因:不清楚)

    方法二、不要使用AOP注解,在xml 中配置需要的AOP 方式,如下:自定义LoggingInterceptor 中有个around 方法

    

<bean id="loggingInterceptor" class="com.bkc.core.aspectj.LoggingInterceptor" />	  <aop:config>
		<aop:aspect id="loggingAspect" ref="loggingInterceptor">
			<aop:pointcut id="loggingIn" expression="execution(* com.bkc.oa.controller..*.*(..))" />
			<!--
			<aop:before method="before" pointcut-ref="loggingIn"/>
			<aop:after method="after" pointcut-ref="loggingIn"/> -->
			<aop:around method="around" pointcut-ref="loggingIn"/>
		</aop:aspect>
	</aop:config>

  

时间: 2024-10-22 20:31:55

引入AOP 报错 error at ::0 formal unbound in pointcut的相关文章

error at ::0 formal unbound in pointcut

在使用声明方式的AOP编程中,遇到以下两个问题,解决方法如下: (1)error at ::0 formal unbound in pointcut 解决方法:去掉函数通知函数中的参数,比如:将 @Before("execution(public void com.bjsxt.dao.impl.UserDAOImpl.*(..))") public void beforeMethod(Method method){ System.out.println("method bef

Spring: aop自动标注时出现 “0 formal unbound in pointcut&quot;

异常代码信息: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in class path resource [cn/czk/test06/bean.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentExceptio

spring异常-aoperror at :0 formal unbound in pointcut

练习spring的后置增强时遇到了如下问题: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemAction2' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested excepti

springAOP注解方式定义切入点报错error at ::0 can&#39;t find referenced pointcut

[说明] 1.使用spring版本:4.0.4 2.springAOP相关依赖包: 1)aopalliance-1.0.jar 2)aspectjweaver-1.8.9.jar 3)aspectjrt-1.8.9.jar 3.分析: 1)当切面类的方法上通知注解直接输入切入点表达式时,没有报错.切面类代码如下: import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect

Java入门到精通——调错篇之Spring2.5利用aspect实现AOP时报错: error at ::0 can&#39;t find referenced pointcut XXX

一.问题描述及原因. 利用Aspect注解实现AOP的时候出现了error at ::0 can't find referenced pointcut XXX.一看我以为注解写错了,结果通过查询相关资料是因为Spring2.5与中的aspectjweaver.jar 和aspectjrt.jar这两个jar包与JDK1.7不匹配. org.springframework.beans.factory.BeanCreationException: Error creating bean with n

Spring AOP报错

八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息: Refreshing org[email protected]277050dc: startup date [Mon Aug 01 22:08:48 CST 2016]; root of context hierarchy 八月 01, 2016 10:08:48 下午 org.

vue2.0+按需引入element-ui报错

项目使用vue脚手架自动生成的,vue版本为^2.5.16.项目中需要按需使用element-ui,根据element-ui的官方文档,一开始在babel.config.js文件中修改配置 module.exports = { presets: [ "@vue/app", ["es2015", { "modules": false }] ], "plugins": [["component", [ { &q

安装Scrapy报错 error: Microsoft Visual C++ 14.0 is required解决方法

[问题背景]:在Windows 10系统,pip install Scrapy,报错error: Microsoft Visual C++ 14.0 is required,还有提示Twisted需要安装. [解决方法步骤] 1.根据提示,去https://landinghub.visualstudio.com/visual-cpp-build-tools下载C++编译工具.但是,页面已经打不开,无法下载.  2.之前因需要安装uwsgi,在Windows 10 安装过MinGW,通过可以Min

Asp.Net程序报错 - error CS2001: Source file &#39;C:\Windows\TEMP\eulevokb.0.cs&#39; could not be found warning CS2008

一个Asp.Net项目,Excel导入功能出现如下错误:error CS2001: Source file 'C:\Windows\TEMP\eulevokb.0.cs' could not be foundwarning CS2008: No source files specified 本地执行是没有问题的,访问正式服务器就会出现这样的错误,搜索一下,原来是权限的问题. 解决办法:打开C盘,找到C:\Windows\TEMP目录,给temp添加IIS_IUSER的权限就没有问题了! Asp.