2016-05-13 5 views
0

私はmavenを使用していて、src/main/resourcesの下に自分のconfigファイルを "singleton-config.xml"として含めました。Springワイルドカードが動作しない

私はそれが正常に動作しているが、私は、ワイルドカード

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:singleton-*.xml"); 

を使用する場合には、例外に

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'singleton' is defined. 

おかげ

答えて

0

使用を与えている

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:singleton-config.xml"); 

としてコンテキストを作成していますウィルクラスパスの後dcard( "クラスパス*")

ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:singleton-*.xml"); 

説明

クラスパス*:ポータビリティクラスパス*:接頭

XMLベースのアプリケーションコンテキストを構築し、位置文字列 は特別なクラスパス*を使用することがあります:接頭辞:

ApplicationContext ctx = 
    new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml"); 

この特別なプレフィックスは、指定された名前 と一致するすべてのクラスパスのリソースが(内部的に、これは本質的ClassLoader.getResources(...)呼び出しを介して 起こる)が得られ、その後、合併しなければならないことを指定します 最終アプリケーションコンテキスト定義。

詳細については、Wildcards in application context constructor resource pathsを参照してください。

+0

なぜclasspath *を教えてください? –

+0

私はそれを私の答えに加えました。 –

関連する問題