2

Eclipse の「動的 Web プロジェクト」と、そのプロジェクトを使用するように Eclipse で構成された Tomcat サーバーがあります。サーブレットにマップされたファイル拡張子があり、サーブレット構成には、次のような component-scan 要素のセットアップがあります。

<context:component-scan base-package="com.mycompany.web" />

Web サーバーが起動すると、ログに次のエラー メッセージが表示されます。

May 6, 2011 9:50:23 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet cap
java.lang.IllegalArgumentException: Resource path [C:\...\src\main\webapp\WEB-INF\classes\com\mycompany\web] does not denote a directory

そのディレクトリは存在しません (パッケージ化された .war ファイルを除く)。ただし、com.mycompany.web パッケージは存在します。

コンポーネントスキャンを行う別の方法はありますか? 別のフォルダーを調べるか、何らかの形で私のプロジェクトなどで見つける必要があります...

4

2 に答える 2

1

やりたいことをすることは可能ですが、少し余分な設定が必要です。

@Controller、@ Repository、またはその他のSpringステレオタイプアノテーションを使用してクラスにアノテーションを付けることができ、Springはそれらを自動的に取得します。

context:component-scanまたは、もう少し情報を提供することもできます。例:

<context:component-scan base-package="com.mycompany.web">
    <!-- scan all classes in the com.mycompany.web package (but
         not in subpackages) -->
    <context:include-filter type="aspectj" expression="com.mycompany.web.*"/>


    <!-- or if you want to include subpackages this config scans all
         classes in com.mycompany.web.special and in its subpackages
         (that's what the ..* means) -->
    <context:include-filter type="aspectj" expression="com.mycompany.web.special..*"/>
</context:component-scan>

最後に、aspectjを使用したくない場合は、context:include-filtertypeを正規表現、カスタムアノテーションなどにすることができます。詳細については、このリンクを参照してください。

于 2011-07-19T16:15:45.853 に答える