[Solved] Import AOP Error: error at ::0 formal unbound in pointcut

An error is reported when AOP is used

九月 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)

 

In AOP programming using declarative mode, the following problems are encountered and the solutions are as follows:

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

Solution: remove the parameters in the function notification function, such as

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

public void   beforeMethod(Method method){

System.out.println(“method before”);

}

Change to

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

public void   beforeMethod(){

System.out.println(“method before”);

}

Case 2:

Original writing:

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

……

}

The following error will be reported:

0 formal unbound in pointcut

 

The reason is that args should be used to indicate the parameter, which can be changed to the following:

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

……

}

There are no parameters in the method. This bug is not for this reason

(2) Possible cause (my guess, unconfirmed)

After using AOP (spring), the annotation is implemented by proxy. There are two kinds of agents: JDK’s own agent and cglib. When using automatic annotation directly in spring MVC, this layer of agent is not used. The annotation naming methods of interfaces and interface implementation classes are inconsistent, resulting in that the agent does not know which class to choose during automatic injection

Possible solutions: first, use AOP annotation to unify the naming of the original business interfaces and interface implementation classes. Suppose the interface is iuserdao and the implementation class is userdaoimpl, which is written during automatic injection   IUserDao userDaoImpl  ( Cause: unclear)

 

Method 2. Do not use AOP annotations. Configure the required AOP methods in XML as follows: there is an around method in the custom logginginterceptor

<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>

Similar Posts: