Unexpected exception parsing XML document from class path resource [applicationContextTransaction.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'logAspect' for bean class [practice.common.AOP.spring.noAction.LogAspect] conflicts with existing, non-compatible bean definition of same name and class [practice.common.AOP.spring.Action.LogAspect]
大致意思是类名冲突,原因是我在配置信息中把两个不同包同一类名的LogAspect类自动扫描进了spring容器
如图
2个LogAspect类均添加了@Component注解
applicationContext.xml
<context:component-scan base-package="practice.common.AOP.spring"/>
扫描时将2个LogAspect都扫描进了Context,导致无法辨别。
解决方法1:通过注解区分。2个LogAspect类分别这样标注,@Component("aspect1") @Component("aspect2")
解决方法2:扫描时base-package再细化一下,比如base-package="practice.common.AOP.spring.Action"