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

摘要:
接口和接口实现类的注释命名方法不一致,这导致代理在自动注入时不知道选择哪个类……解决方案是:1.使用AOP注释来统一原始业务接口和接口实施类的命名。

使用了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.pluginsorg.eclipse.wst.server.core	mp0wtpwebappspmpWEB-INFclassescomkcpmpxdjzcserviceimplAccountServiceImpl.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.pluginsorg.eclipse.wst.server.core	mp0wtpwebappspmpWEB-INFclassescomkcpmpxdjzcserviceimplAccountServiceImpl.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     />	
  <aop:config> <aop:aspect ref="loggingInterceptor"> <aop:pointcut 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>

  

免责声明:文章转载自《引入AOP 报错 error at ::0 formal unbound in pointcut》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Object.defineProperty() 吴小明CentOS7安装weblogic集群思路梳理下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

利用.NET4.0的DynamicObject来拦截调用实现AOP

利用AOP我们很容易的就能实现类似Log等业务无关的横切关注点,避免了这些代码在项目中不断的重复,利用.NET DLR 我们可以很容易的就实现一个简单的AOP,代码如下: using System;using System.Dynamic;using System.Reflection;namespace Zxf.Practices{public clas...

Red5源代码分析

原文地址:http://semi-sleep.javaeye.com/blog/348768 Red5如何响应rmpt的请求,中间涉及哪些关键类? 响应请求的流程如下: 1.Red5在启动时会调用RTMPMinaTransport的start()方法,该方法会开启rmtp的socket监听端口(默认是1935),然后使用mina(apache的io操作...

AOP拦截器 SpringBoot可以直接导入spring-boot-starter-aop编写AOP拦截器,实现业务层拦截。

AOP拦截器 SpringBoot可以直接导入spring-boot-starter-aop编写AOP拦截器,实现业务层拦截。 AOP(面向切面编程)是Spring提供的重要技术工具,其主要功能是对业务层的方法调用进行拦截处理。SpringBoot默认情况下并没有配置AOP拦截器,开发者需要在项目中手动引入spring-boot-starter-aop依赖...

springboot之多数据源配置JdbcTemplate

springboot多数据源配置,代码如下 DataSourceConfig package com.rookie.bigdata.config; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.contex...

No qualifying bean of type 'org.springframework.transaction.TransactionManager' available: more than one 'primary' bean found among candidates:

完整的异常提示信息: No qualifying bean of type 'org.springframework.transaction.TransactionManager' available: more than one 'primary'bean found among candidates: [dataBaseOneTransactionMa...

java与json互相转换(解决日期问题)

JSON 即 JavaScript Object Natation,它是一种轻量级的数据交换格式,非常适合于服务器与 JavaScript 的交互。本文主要讲解下java和JSON之间的转换,特别是解决互相转换遇到日期问题的情况。 一、需要相关的jar包: json-lib-xxx.jar ezmorph-xxx.jar c...