私はクラスのほとんどを下に置きました
com.company.productline.product -- classpath 1
そのクラスパス内には、サービス、Web、ドメイン、i18n...サブパッケージがあります。
何らかの理由で、私が瓶に包んだ別のサービスBeanがあります。これは、製品ライン全体で機能するはずです。
com.company.productline -- classpath 2
したがって、applicationContext.xmlでは、コンポーネントスキャンの基本パッケージは、次のように、クラスパス1ではなくクラスパス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がその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]'
問題は、Springが真ん中にcom.company.productline.i18n.someServiceClass
ない偽のパッケージの下でBeanクラスを見つけたようですが、これが私が確認できることです:product
パッケージの下にクラス/クラスパスはありませんが、の下にクラス
com.company.productline.i18n.someServiceClass
がありcom.company.productline.product.i18n.someServiceClass
ます。クラス
someServiceClass
には@Componentアノテーションがあります。
しかし、でクラスパスを1レベル下げると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;
}
}
だから、何が起こっているのか、なぜこの問題があるのか本当にわかりません。
アプリケーションは、STS2.9.1のSpring3.1.0で実行されています。
よろしくお願いします。