【发布时间】:2018-05-12 08:50:12
【问题描述】:
背景:我在一个名为com.x.myproject 的项目中工作。我依赖于另外两个包com.x.document 和com.x.library。两个包都有同一个类,名称为QueueHelper。
现在,在我的项目中,我必须扫描另一个包com.x.security,它在内部扫描com.x,类似这样:
@SpringBootApplication
@ComponentScan(basePackages = {"com.x"})
@EnableCaching
public class Security {
.......
}
在 com.x.myproject 中
@SpringBootApplication
@ComponentScan(basePackages = {"com.x.myproject","com.x.security"}, excludeFilters={
@ComponentScan.Filter(type=FilterType.REGEX, pattern="com.x.document.*"),
@ComponentScan.Filter(type=FilterType.REGEX, pattern="com.x.library.*")})
public class MyProject{
.......
}
当我在com.x.security 中使用excludefilters 时一切正常,但我想在com.x.myproject 中使用它
我得到的异常是
Annotation-specified bean name 'queueHelper' for bean class [com.x.library.utils.QueueHelper] conflicts with existing, non-compatible bean definition of same name and class [com.x.document.utils.QueueHelper]
【问题讨论】:
-
一个非个人的解决方案可能是一个命名策略:docs.spring.io/spring-javaconfig/docs/1.0-m2/reference/html/…
标签: java spring spring-boot exception