切入点格式不正确:在角色位置12处期待')'

时间:2017-05-31 16:55:06

标签: spring-aop

 public interface Performance {
        public void perform();
    }
    @Component
    public class PerformanceImpl implements Performance {

        @Override
        public void perform() {
            // TODO Auto-generated method stub
            System.out.println(this.getClass()+"演出...");
        }

    }
    public class Main {

        public static void main(String[] args) {
            // TODO Auto-generated method stub
             //1、创建Spring的IOC的容器  
            ApplicationContext ctx = new ClassPathXmlApplicationContext("springXml/concertConfig.xml");  
            Performance p = ctx.getBean(Performance.class);
            p.perform();

        }

    }
@Component
@Aspect
public class Audience {

    @Pointcut("exection(** concert.Performance.perform(..))")
    public void performance(){}

    @Before("performance()")
    public void silenceCellPhones(){
        System.out.println("Silence cell phones");
    }
    @Before("performance")
    public void takeSeats(){
        System.out.println("Taking seats");
    }
    @AfterReturning("performance()")
    public void applause(){
        System.out.println("CLAP CLAP CLAP!");
    }
    @AfterThrowing("performance()")
    public void demandRefund(){
        System.out.println("Demanding a refund");
    }

}

我注意到这个问题,我终于解决不了

config xml:

 <context:component-scan base-package="concert"></context:component-scan>
 <aop:aspectj-autoproxy> </aop:aspectj-autoproxy>

我遇到的问题

六月 01, 2017 6:41:12 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@49c2faae: startup date [Thu Jun 01 06:41:12 CST 2017]; root of context hierarchy
六月 01, 2017 6:41:13 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [springXml/concertConfig.xml]
六月 01, 2017 6:41:13 上午 org.springframework.context.support.ClassPathXmlApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performanceImpl' defined in file [D:\cmj\MyProject\eclipse\springWorkspace\spring2\bin\concert\PerformanceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
            ^^^^^^^

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at concert.Main.main(Main.java:11)
Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
            ^^^^^^^

    at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:316)
    at org.aspectj.weaver.reflect.InternalUseOnlyPointcutParser.resolvePointcutExpression(InternalUseOnlyPointcutParser.java:36)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getDeclaredPointcuts(Java15ReflectionBasedReferenceTypeDelegate.java:299)
    at org.aspectj.weaver.ReferenceType.getDeclaredPointcuts(ReferenceType.java:790)
    at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:237)
    at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:235)
    at org.aspectj.weaver.Iterators$4$1.hasNext(Iterators.java:213)
    at org.aspectj.weaver.Iterators$4.hasNext(Iterators.java:230)
    at org.aspectj.weaver.ResolvedType.findPointcut(ResolvedType.java:722)
    at org.aspectj.weaver.patterns.ReferencePointcut.resolveBindings(ReferencePointcut.java:149)
    at org.aspectj.weaver.patterns.Pointcut.resolve(Pointcut.java:188)
    at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:313)
    at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:294)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:280)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:330)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    ... 11 more

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'performanceImpl' defined in file [D:\cmj\MyProject\eclipse\springWorkspace\spring2\bin\concert\PerformanceImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
            ^^^^^^^

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at concert.Main.main(Main.java:11)
Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting ')' at character position 12
exection(** concert.Performance.perform(..))
            ^^^^^^^

    at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:316)
    at org.aspectj.weaver.reflect.InternalUseOnlyPointcutParser.resolvePointcutExpression(InternalUseOnlyPointcutParser.java:36)
    at org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate.getDeclaredPointcuts(Java15ReflectionBasedReferenceTypeDelegate.java:299)
    at org.aspectj.weaver.ReferenceType.getDeclaredPointcuts(ReferenceType.java:790)
    at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:237)
    at org.aspectj.weaver.ResolvedType$PointcutGetter.get(ResolvedType.java:235)
    at org.aspectj.weaver.Iterators$4$1.hasNext(Iterators.java:213)
    at org.aspectj.weaver.Iterators$4.hasNext(Iterators.java:230)
    at org.aspectj.weaver.ResolvedType.findPointcut(ResolvedType.java:722)
    at org.aspectj.weaver.patterns.ReferencePointcut.resolveBindings(ReferencePointcut.java:149)
    at org.aspectj.weaver.patterns.Pointcut.resolve(Pointcut.java:188)
    at org.aspectj.weaver.tools.PointcutParser.resolvePointcutExpression(PointcutParser.java:313)
    at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:294)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:207)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
    at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:194)
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:248)
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:280)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:330)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    ... 11 more

我已经看到了问题similar,但它无法解决我的问题。为什么会出现这样的错误?

1 个答案:

答案 0 :(得分:1)

切入点名称不应为exectionexecution**应为*

execution(* concert.Performance.perform(..))