2016-07-24 7 views
0

JSF 2終了Spring 4.3を使用したWebモジュールがあります。バッキングBeanでは、JARのサービスのDIとして@Autowiredを使用します。 EARモジュールには、Spring、@ServiceのSpringとJAR、Springの設定ファイルを持つJARがあります。Spring @Autowired(必須= true)がnullです

<context-param> 
     <param-name>locatorFactorySelector</param-name> 
     <param-value>classpath:beanRefContext.xml</param-value> 
    </context-param> 

    <context-param> 
     <param-name>parentContextKey</param-name> 
     <param-value>sharedContext</param-value> 
    </context-param> 
    <context-param> 
    <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:applicationContext.xml</param-value> 
    </context-param> 
<listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <listener> 
     <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
    </listener> 

applicationContext.xmlweb.xmlスニペット以下

<context:annotation-config /> 
    <context:spring-configured /> 
<!-- package of @Service class in jar module in EAR-- > 
    <context:component-scan base-package="com.ipdb.service" /> 

beanRefContext.xml:私はバッキングBeanで@Autowired(required=null)を使用すると値が存在null(ある

<bean id="sharedContext" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> 
    <list> 
     <value>spring-ctx.xml</value> 
    </list> 
</constructor-arg> </bean> 

例外ではありません)。私のJSF bean

@Component 
@ManagedBean 
@ViewScoped 
public class PortfolioController { 


    @Autowired(required = true) 
    private PortfolioService portfolioService; 

... 

私を助けてください。

+1

を注入これは、Spring Beanと春が管理するか、またはそれをオートワイヤリングされていないではありません。 – chrylis

+0

あなたの質問は最初に[spring-mvc]とタグ付けされていましたので、考えてみましょう:http://stackoverflow.com/q/18744910 – BalusC

答えて

2

PortfolioController@ManagedBean@Componentを追加JSFコンテキストBeanが使用すると、2つの異なるコンテキスト(JSFSpring)でBeanとして同じクラスをマークすることはできません完全に間違っていると考えられています。

2つの溶液のいずれかPortfolioController春の豆を作るため@ManagedBeanを削除し、@ViewScopedまたはPortfolioControllerJSFを経由して射出注釈@ManagedProperty

@ManagedProperty("#{portfolioService}") 
private PortfolioService portfolioService; 
+0

[OK]を '@ManagedBean'で' @ Autowired'を削除しました。実装サービスが検出されましたが、このエラーがあります: 'タイプcom.ipdb.service.portfolio.impl.PortfolioServiceImplの[email protected]をインタフェースcom.ipdb.serviceに変換できません.PortfolioService'。 'PortfolioServiceImpl'は' PortfolioService'を実装します。私を助けてくれますか? –

+0

私は解決しました、それはpomの依存問題でした;) –

0

applicationContext.xmlあなたのjarファイルの依存関係にある場合、あなたはクラスパスの後にアスタリスクを追加する必要があります。

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

クラスパスだけではなく、現在のプロジェクトにアスタリスクスプリング検索ファイルapplicationContext.xmlどこかで。

関連する問題