0

私はクラスのほとんどを下に置きました

  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

  1. パッケージの下にクラス/クラスパスはありませんが、の下にクラスcom.company.productline.i18n.someServiceClassがありcom.company.productline.product.i18n.someServiceClassます。

  2. クラス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で実行されています。

よろしくお願いします。

4

1 に答える 1

0

ニンが正しいことがわかりました。他の可能性はありませんが、アプリケーション内で同じBean名を持つクラスのみです。

この場合、プロジェクト検索が機能しない理由は、同じサービスクラスを持つ別のjarファイルがあるためです。気が付くまでそれを知りませんでした。ソースコード内のクラスを削除すると、エラーはなくなります。

ありがとうニン。

于 2013-01-15T15:24:27.993 に答える