完整報錯如下:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beforeAdvice' defined in class path resource [applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJPointcutAdvisor]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed: expecting 'name pattern' at character position 10
execution()
出現了一種<aop:config>標簽與bean無法共存的現象,一開始以為是aspectj 包的版本問題,可修改來修改去,還是報錯。
解決方案:后來發現,還是因為excution()內的表達式寫錯了,修改后運行成功。
<aop:config>
<aop:aspect id="beforeAspect" ref="beforeAdvice">
<aop:before method="methodBefore" pointcut="execution(* com.ph.service..*.*(..))"/>
</aop:aspect>
</aop:config>
如果排除了版本不匹配、注解沒寫等問題后,還是報錯,就要考慮是不是execution表達式寫錯了。