猿问

aspectj 注解中 execution()的问题

错误如下



包结构如下


https://img4.mukewang.com/5cb970de000198f903690343.jpg


这是我的方法


@Before("execution(*com.wisely.highlight_spring4.ch1.aop.DemoMethodService.*(..))")

    public void before(JoinPoint joinPoint){

        MethodSignature signature=(MethodSignature)joinPoint.getSignature();

        Method method=signature.getMethod();

        System.out.println("方法规则拦截"+method.getName());

    }

这是运行的错误


Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.event.internalEventListenerProcessor': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 68

execution(*com.wisely.highlight_spring4.ch1.aop.DemoMethodService.*(..))

                                                                    ^


    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:306)

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)

    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)


网上查了各种资料.*(..)就是执行所有方法的意思啊,为什么这里会报错?


MMTTMM
浏览 948回答 2
2回答

阿波罗的战车

我猜问题可能是你少了一个空格@Before("execution(* com.wisely.highlight_spring4.ch1.aop.DemoMethodService.*(..))")public void before(JoinPoint joinPoint){    MethodSignature signature = (MethodSignature)joinPoint.getSignature();    Method method = signature.getMethod();    System.out.println("方法规则拦截"+method.getName());}问题在这* com.wisely

有只小跳蛙

Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 68execution(*com.wisely.highlight_spring4.ch1.aop.DemoMethodService.*(..))你检查你的声明切入点表达式那里有没有错,括号的两个点(..)是没有错的
随时随地看视频慕课网APP

相关分类

Java
我要回答