1

web.xml に次のものがあります。

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

私は2つのファイルを持っています:

  • web.xml の隣にある WEB-INF の applicationContext-web.xml
  • myapp-service.jar 内の applicationContext-service.xml

アプリをデプロイすると、

依存関係に一致するタイプ [AServiceBean] の Bean が見つかりません: この依存関係のオートワイヤー候補として適格な少なくとも 1 つの Bean が必要です。

applicationContext-service.xml が見つからないようです。web.xml の横にコピーすると、正常に動作します。なぜこれが起こるのか分かりません。

サーバーは Tomcat 6 です。

どんな助けでも大歓迎です。ありがとう。

編集

明確にするために:私が使用する場合

<param-value>
    classpath:applicationContext-web.xml,
    classpath:applicationContext-service.xml
</param-value>

アプリは問題なくデプロイされるため、applicationContext-service.xml を見つける (または見つけない) だけです。

4

2 に答える 2

3

使ってみてくださいclasspath*:applicationContext-*.xml(コロンの前にアスタリスクがあります)。

ただし、JBoss に問題があるなど、動作しない場合があります。動作させるには、jboss の特別なクラス ローダーを使用する必要があります。

また、ルートでパターンを使用すると、いくつかの問題があります。

とにかく、パターンを避けることをお勧めapplicationContext.xmlします。2 つの明示的なimportステートメントを使用することをお勧めします。

于 2011-12-06T14:51:48.350 に答える
1

構成ファイルをクラスパスに配置する必要があります。

WEB-INF/classess  is the directory you need to place your configuration files
classpath:applicationContext-*.xml will then work

または、これに似た sth を使用して、それらを 1 か所に保持します

WEB-INF/classes/spring   
classpath:spring/applicationContext-*.xml

applicationContext-service.xml : jar ファイルに既にある場合は、これをコピーする必要はありません


サンプルの main-config.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd         
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


<import resource="classpath:spring/config1.xml" />
<import resource="classpath:spring/config2.xml" />
.
.
<import resource="classpath:spring/configN.xml" />


</beans>
于 2011-12-06T15:39:01.957 に答える