新手刚学习Spring,使用注解时
@Before("execution(*com.zhazhapan.spring.springtest.chapter.one.aop.DemoMethodService.*(..))")
总是报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aopConfig': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 79
execution(*com.zhazhapan.spring.springtest.chapter.one.aop.DemoMethodService.*(..))
^
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:84)
at com.zhazhapan.spring.springtest.chapter.one.aop.Main.main(Main.java:14)
Caused by: java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 79
终于在stackoverflow上面找到了解决方案,原来是*之间需要空格,修改注解如下即可
@Before("execution(* com.zhazhapan.spring.springtest.chapter.one.aop.DemoMethodService.* (..))")
//注意多了空格哦