UnsupportedPointcutPrimitiveException on simple AOP example

…衆ロ難τιáo~ 提交于 2019-12-11 03:27:25

问题


I try to run a simple aop example in this site. I have spring aop and aspectj, aspectjweaver jars:

@Aspect
public class StringAspect {

    @Pointcut("call(* String.toLowerCase())")
    public void toLowerCasePointcut() {}

    @Around("toLowerCasePointcut()")
    public String toLowerCaseAroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        String text = ((String) joinPoint.getTarget()).toUpperCase();
        return text;
    }
}

When I run this example in Test.java like "AaBbCc".toLowerCase(), I get this exception;

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean ... Initialization of bean failed; nested exception is org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException: Pointcut expression call(* String.toLowerCase()) contains unsupported pointcut primitive 'call'

Spring AOP doesnt contain "call", but why aspectj weaving is not working, ,do you have an idea? Thank you.

edit:

In my spring config file I only have bean definition of @aspect annotated class and <aop:aspectj-autoproxy />. my jars are : spring-aop-3.0.5, aopalliance, aspectjrt1.6.8, aspectjweaver1.5.0


回答1:


Have you tried to use the AspectJ Eclipse plugin to do the weaving? (It is also included in SpringSource Tool Suite)

If you have some aspect configuration in your Spring configuration. Try to remove it and just enable AspectJ nature on the project. Also remove all AspectJ jar files and only use those that is attached automatically by the plugin.

With this setup it works for me at least.

Updated: Weaving the aspect advice into code

You get an exception from the Spring container because of your call pointcut. But you want AspectJ weavingweave the aspect. Then you need to use either compile-time or load-time weaving. Compile-time weaving is the simplest alternative ant the alternative offered by the plugin.

You can look at the AspectJ compiler as an advanced Java compiler that also supports AspectJ. So you can run your compiled code anywhere.

Also, you do not need the plugin to compile. You can for example compile with an Ant task as I have showed here.

But the easiest alternative is to use the plugin. This also gives you extra help which I have described briefly here.

I hope this helps!



来源:https://stackoverflow.com/questions/6516390/unsupportedpointcutprimitiveexception-on-simple-aop-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!