3

プロジェクトでSpring3を使用していますが、JARファイルからSpringBeanを注入すると問題が発生します。JARファイルには、次のようなクラスがあります。

package test;

@Service("CommonService")
public class CommonService {
}

そして、私はすでにそれをこのように使用しました。

package com.java.test.app;

@Service(value = "OtherService")
public class OtherService {
    @Resource(name = "CommonService")
    private CommonService service;
}

私の春-beans.xml;

<context:component-scan base-package="com.java.test.app, test">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>

しかし、@Resourceアノテーションは機能しません。JARファイルからSpring Beanを注入できますか?

4

1 に答える 1

0

実行時にCommonServiceクラスがクラスパス上にあり、component-scanで指定した基本パッケージ内にある場合は、問題ありません。@Resourceの代わりに@Autowiredを使用してみてください。

于 2012-11-09T17:53:47.017 に答える