本文介绍了简单AOP示例上的UnsupportedPointcutPrimitiveException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在网站中运行一个简单的aop示例.我有spring aop和Aspectj,Aspectjweaver罐子:

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

当我在Test.java中运行此示例(例如"AaBbCc" .toLowerCase())时,出现此异常;

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不包含"call",但是为什么AspectJ编织不起作用,您有什么主意吗?谢谢.

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

在我的spring配置文件中,我只有@aspect注释类和<aop:aspectj-autoproxy />的bean定义.我的罐子是:spring-aop-3.0.5,aopalliance,aspectjrt1.6.8,aspectjweaver1.5.0

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

推荐答案

您是否尝试过使用AspectJ Eclipse plugin 做编织? (它也包含在 SpringSource工具套件中)

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

如果您的Spring配置中有某些方面的配置.尝试将其删除,仅在项目上启用AspectJ特性.还要删除所有AspectJ jar文件,仅使用插件自动附加的文件.

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.

已更新:将方面建议编入代码

由于调用切入点,您将从Spring容器中获取异常.但是您希望AspectJ编织编织方面.然后,您需要使用编译时编织或加载时编织.编译时编织是插件提供的最简单的选择.

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.

您可以将AspectJ编译器视为也支持AspectJ的高级Java编译器.因此,您可以在任何地方运行编译后的代码.

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.

我希望这会有所帮助!

这篇关于简单AOP示例上的UnsupportedPointcutPrimitiveException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:26