2016-04-11 25 views
0

私はプロジェクトに3つのモジュールを持っています。そのうちの1人がcommonに電話します。このモジュールでは、私はSpringコンテナを開始しようとしています。 1つの豆は別のモジュール(webapp)に住んでいて、私はモジュールtestappを持っています。だから今、サーバー(Webアプリケーションと共通)でプロジェクトを展開した後、それはすべてOKですが、私は一般的な展開とTestAppがしようとした場合、それは例外で失敗しますbeanが存在しない場合、springコンテナに失敗しません。

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class[...] 

私はそれを無視するすべての可能性であるかどうかを知るためにwhant存在しない豆と容器を運ぶ?私はxmlの設定を使用していますが、注釈はありません。ビジネスロジックのため、正確にxmlにする必要があります

答えて

1

特定のBeanをインスタンス化する時期を判断するためにSpringプロファイルを使用します。たとえば、あなたは

<?xml version="1.0" encoding="UTF-8"?> 
<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.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"> 

    <!-- define common beans here--> 
    <beans profile="test"> 
     <!-- define test beans here--> 
    </beans> 
    <beans profile="web"> 
     <!-- define web beans here--> 
    </beans> 
</beans> 

を次のようにどのように応じて、次に、あなたの豆を定義し、アプリケーションのコンテキストxml構成に続いて2つのプロファイル(共通+のWebアプリケーションのための)ウェブおよび(共通+のtestappと用)テスト

を持つことができますアプリケーションを起動するには、spring.profiles.activeというシステム・プロパティーを指定して、使用するプロファイルを指定する必要があります。

たとえば、-Dspring.profiles.active = webまたは-Dspring.profiles.active = test

+0

wow!男性、これは本当にクールな解決策です!ありがとう! – Dante

+0

このソリューションの詳細については、[link](http://www.captaindebug.com/2012/08/using-spring-profiles-in-xml-config.html#.VwyzZzTBn1w) – Dante

関連する問題