2016-08-11 2 views
2

春にWildflyで戦争の外にあるWildFlyからプロパティファイルを読み込む必要があります。春にPropertyPlaceholderConfigurerを使用して試しましたが、問題は1つあります。バネを使用した外部パスからのロードプロパティファイル

applicationContext.xmlを

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location"> 
     <value>file:/C:\wildfly-9.0.2.Final\wildfly-9.0.2.Final\standalone\deployments\/propertyLoader.properties</value> 
    </property> 
</bean> 

<bean id="getPropertyBean" 
    class="com.csc.loadProperty.GetProperty"> 
    <property name="prefixProp" value="${prefix}" /> 
    <property name="suffixProp" value="${suffix}" /> 
    <property name="newProp" value="${new}" /> 
</bean> 

ここで私はpropertyLoader.propertiesの絶対パスを与えているが、私はパスが異なるマシンに異なることができるように、サーバーからの相対パスを与える必要があります。誰でも助けてくれますか?あなたは、スプリング4を使用している場合

答えて

1

、その後、$ {}

@Configuration 
@PropertySource("file:${app.home}/app.properties") 
public class AppConfig 
@Autowired 
Environment env; 
} 

を使用して、プロパティファイルのパスを指定すると、起動時にシステム変数としてapp.homeことを設定します。いくつかのコンテナの中でSpringアプリケーションを実行する場合は、java起動オプションまたはvm引数にこのプロパティを設定します。

java -jar -Dapp.home="/home/dev/config" example.jar 
0
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location"> 
     <value>file:# C:/wildfly-9.0.2.Final/wildfly-9.0.2.Final/standalone/deployments/propertyLoader.properties</value> 
    </property> 
</bean> 
関連する問題