我已經把大部分的類的下基本包組件掃描拿起錯分裝
com.company.productline.product -- classpath 1
那類路徑中會有服務,網站,域名,國際化......子包。
出於某種原因,存在另一服務豆我包裹在一個罐子,它應爲全PRODUCTLINE工作,因此它是
com.company.productline -- classpath 2
所以在applicationContext.xml中下,基部包組件-Scan不得不妥協到了一個水平,類路徑2,而不是1 classpath中,像這樣
<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>
然後使春天,甚至內的jar文件掃描@Service或@Component在整個應用程序。
然而,現在的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]'
問題是春天似乎找到一個假包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;
}
}
所以真的不知道發生了什麼,爲什麼會有這個問題。
該應用程序是事先在春天3.1.0運行在STS 2.9.1
請幫忙,謝謝。
你能否確認你的applicationContext沒有手動的bean配線尋找類com.company.productline.i18n.someServiceClass?搜索整個項目的線路,看看它出現了什麼。 – ninnemannk
謝謝@ninn。我認爲在這種情況下,那麼類名應該出現在XML的權利?我做了一個完整的項目搜索,但沒有找到類名顯示在任何XML文件,既沒有屬性文件。 – Dreamer
是的。這絕對是奇怪的,沒有聽說過之前發生過的事情。這幾乎聽起來像你最近把你的「someServiceClass」移動到一個新的包,但你的包裝結構和服務器不知道它。嘗試從自己的服務器清理你的服務(刪除你的可部署的戰爭,耳朵等)。然後做一個完整的乾淨安裝,我假設你使用Maven,並再次部署。 – ninnemannk