2017-06-08 38 views
0

我正在使用SwithcYard 2.0.0.Beta1。應用程序服務器是WildFly 8.1。我想從模塊加載屬性。 如實例我有一個模塊/ wildfly /模塊/系統/層/基層/組織/學習/配置/測試 我module.xml從wildfly模塊注入駱駝路由的屬性

<?xml version="1.0" encoding="UTF-8"?> 
<module xmlns="urn:jboss:module:1.3" name="org.study.configuration" slot="test"> 
    <resources> 
     <resource-root path="."/> 
    </resources> 
</module> 

這是屬性文件:

user=foo 
password=bar 
provider=CryptoProvider 
directory=domain;login:[email protected]/dir?password=pwd&preMove=backup&move=processed&moveFailed=error&charset=UTF-8 

這我就是包括wildfly配置文件模塊:

<subsystem xmlns="urn:jboss:domain:ee:2.0"> 
     <global-modules> 
      <module name="org.study.configuration" slot="test"/> 
     </global-modules> 

現在我想要加載,在我的駱駝路徑屬性:

.to("smb://{{directory}}") 

或 在豆

KeyStore ks = KeyStore.getInstance("PKCS12", {{provider}}); 

這可能嗎?這個怎麼做?

回答

0

這是可能的,但只要您的屬性在文件中,您必須首先加載它。

你在模塊中定義了什麼 - 它只是你的應用程序的類路徑。

如果您使用Java DSL:如果您使用Spring DSL只定義普通的Spring性能

Properties myProps = new Properties(); 

Stream is = this.getClass().getClassLoader().getResourceAsStream("MyAppProp.properties"); 
myProps.load(is);  
System.getProperties().putAll(myProps); 

a。用Spring bean命名空間

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
    <property name="location"> 
     <value>MyAppProp.properties</value> 
    </property> 
</bean> 

b。與Spring上下文命名空間

<context:property-placeholder location="MyAppProp.properties"/> 

然後就像你說的,你可以用它們駱駝航線內:

.to("smb://{{directory}}") 

PS。你也可以直接在module.xml中定義屬性

<module xmlns="urn:jboss:module:1.3" name="org.study.configuration" slot="test"> 
    <properties> 
    <property name="directory" value="myTestDirectory"/> 
    </properties> 
    ...