引入AOP 报错 error at ::0 formal unbound in pointcut
使用了AOP 后启动报错
1 2 3 4 5 6 7 8 9 10 | 九月 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 方法
1 2 3 4 5 6 7 8 9 | <bean id= "loggingInterceptor" class = "com.bkc.core.aspectj.LoggingInterceptor" /> <br> <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> |
作者:panie
出处:http://www.cnblogs.com/panie2015/
如果您希望与我交流互动,欢迎加我微信
本文内容为作者辛苦整理书写,欢迎转载,但请保留文章出处
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?