2017-06-08 40 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> 
    ...