Spring: error at ::0 can‘t find referenced pointcut的错误并解决

Posted scruffybear

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring: error at ::0 can‘t find referenced pointcut的错误并解决相关的知识,希望对你有一定的参考价值。

文章目录

问题

运行Spring测试程序,返回错误: AOP : java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut.

程序如下:

AspectJBean.java

package springcore.aspectj;

public class AspectJBean 

	public void display() 
		System.out.println( "AOPBean.display()!" );
	

AspectJMain.java

package springcore.aspectj;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AspectJMain 

	public static void main(String[] args) 

		ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext( "springcore/aspectj/AspectJBeans.xml" );
		
		AspectJBean aspectJBean = (AspectJBean)factory.getBean( "aspectJBean" );
		aspectJBean.display();
		
	

LoggerAspect.java

package springcore.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class LoggerAspect 

    @Pointcut("execution(public * *(..))")
    public void publicMethods()  

    @Pointcut("execution(* springcore.aspectj.LoggerAspect.*(..))")
    public void logObjectCalls()  

    @Pointcut("publicMethods()&&!logObjectCalls()")
    public void loggableCalls()  

	
    @Around("loggableCalls()")
	public Object aroundLogCalls(ProceedingJoinPoint joinPoint)
			throws Throwable 
		System.out.println("before invoke method:"
				+ joinPoint.getSignature().getName());
		Object object = joinPoint.proceed();
		System.out.println("after invoke method:"
				+ joinPoint.getSignature().getName());
		return object;
	



AspectJBeans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

	<aop:aspectj-autoproxy/>

	<bean id="loggerAspect" class="springcore.aspectj.LoggerAspect"/>
	<bean id="aspectJBean" class="springcore.aspectj.AspectJBean"/>
</beans>

解决

参考stackoverflow: AOP : java.lang.IllegalArgumentException: error at ::0 can’t find referenced pointcut

需要使用更高级一点的版本的aspectjrt.jaraspectj-weaver.jar, 进行Google,然后下载后进行替换,问题解决。

以上问题解决。显示如下:

before invoke method:display
AOPBean.display()!
after invoke method:display

参考

stackoverflow: AOP : java.lang.IllegalArgumentException: error at ::0 can’t find referenced pointcut

以上是关于Spring: error at ::0 can‘t find referenced pointcut的错误并解决的主要内容,如果未能解决你的问题,请参考以下文章

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

SpringAOP注解报错:java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut se

Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut aaa(示

Can't connect to MySQL server (hosted by strato) error: 2013 lost connection to mysql server at 'rea

ERROR 1007 (HY000) at line 29: Can‘t create database ‘qz‘; database exists

ERROR 1840 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBA