Tag Archives: AOP

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

AOP Configuration Services error: javax.persistence.TransactionRequiredException: no transaction is in progress

The transaction configuration is as follows:

Methods of serviceimpl class

Error report

javax.persistence.TransactionRequiredException: no transaction is in progress
	at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:409)
	at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3602)
	at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1483)
	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1479)  

Note: the method name of serviceimpl is find * (); Has been configured as & lt; tx:method name=”find*” propagation=”SUPPORTS”/>

Supports: supports the current transaction. If there is no current transaction, it will be executed in non transaction mode

I don’t understand why javax.persistence.transactionrequiredexception: no transaction is in progress

Later & lt; tx:method name=”find*” propagation=”SUPPORTS”/> Change to & lt; tx:method name=”find*” propagation=”SUPPORTS” read-only=”true”/> Problem solving

Read only applications:

If you execute a single query at a time, it is unnecessary to enable transaction support. The database supports read consistency during SQL execution by default
if you execute multiple query statements at one time, such as statistical query and report query, in this scenario, multiple SQL queries must ensure the overall read consistency, otherwise, after the previous SQL query and before the next SQL query, the data is changed by other users, then the whole statistical query will appear the read data inconsistent state, and at this time, the read data is inconsistent, Transaction support should be enabled
[note that multiple queries are executed at a time to count some information. In this case, read-only transactions are used to ensure the overall consistency of the data]