我把班上的大多数人都关进了
com.company.productline.product -- classpath 1在这类路径中将有服务、web、域、i18n.子包。
由于某些原因,我在jar中包装了另一个服务bean,它应该可以用于整个产品线,因此它位于
com.company.productline -- classpath 2因此在applicationContext.xml中,组件扫描的基本包必须妥协到一个级别上,作为类路径2而不是类路径1,如下所示
<context:component-scan base-package="com.company.productline">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>然后让Spring在整个应用程序中扫描@Service或@Component,甚至在jar文件中。
但是,现在在applicationContext中有一个错误:
Annotation-specified bean name 'someServiceClass' for bean class
[com.company.productline.i18n.someServiceClass] conflicts with existing,
non-compatible bean definition of same name and class
[com.company.productline.product.i18n.someServiceClass]'问题是Spring似乎在一个错误包com.company.productline.i18n.someServiceClass下找到了一个bean类,其中没有product,但是我可以确认如下:
com.company.productline.i18n.someServiceClass下没有类/类路径,但是在com.company.productline.product.i18n.someServiceClass下有一个类。someServiceClass确实有一个@Component注释。但是,如果我将base-package中的类路径降低一个级别,错误就消失了:
<context:component-scan base-package="com.company.productline.product">
<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>类的定义如下:
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "request")
public class SomeServiceClass implements CurrentRequest {
@Autowired
private HttpServletRequest request;
public Locale getCurrentLocale() {
LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
return localeResolver.resolveLocale(request);
}
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
}所以不知道到底发生了什么,为什么会有这个问题。
该应用程序运行在STS 2.9.1上的Spring3.1.0上
请帮忙,谢谢。
发布于 2013-01-15 15:24:27
原来宁恩是对的。没有其他的可能,只有应用程序中的类具有相同的bean名称。
在本例中,项目搜索不起作用的原因是我们有另一个具有相同服务类的jar文件。直到被注意到我才知道。在删除源代码中的类之后,错误就消失了。
谢谢尼恩。
https://stackoverflow.com/questions/14329477
复制相似问题