全て!
私はこのスニペットを持っています:
SomeCustomClassLoader customClassLoader = new SomeCustomClassLoader();
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.setClassLoader(customClassLoader);
ctx.load(new ByteArrayResource(bytesData));
ctx.refresh();
Object testService = ctx.getBean("testService");
カスタムクラスローダーで新しいアプリケーションコンテキストを作成しようとしている場所。コンテキスト ファイルは次のようになります。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
">
<context:annotation-config />
<context:component-scan base-package="some.base.package" />
<bean name="testService" class="some.base.package.TestService"/>
</beans>
質問:コンテキスト ファイルで明示的に宣言されている場合のみTestServiceを取得できるのはなぜですか。このサービスに@Serviceアノテーションがある場合は作成されません。コンポーネントのスキャンを有効にする方法。私のコードで何が間違っていますか?
ありがとう。