【问题标题】:injecting properties in camel route from wildfly modules从 Wildfly 模块在骆驼路线中注入属性
【发布时间】:2017-06-08 12:43:06
【问题描述】:

我正在使用 SwithcYard 2.0.0.Beta1。应用服务器为 WildFly 8.1。我想从模块加载属性。 例如,我有一个模块 /wildfly/modules/system/layers/base/org/study/configuration/test 我的模块.xml

<?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:pwd@host/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}});

有可能吗?如何做到这一点?

【问题讨论】:

    标签: apache-camel wildfly switchyard


    【解决方案1】:

    这是可能的,但只要您的属性在文件中,您就必须先加载它。

    您在模块中定义的内容 - 它只是您的应用程序的类路径。

    如果您使用 Java DSL:

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

    如果您使用 Spring DSL,只需定义常规 Spring 属性。

    一个。使用 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>
      ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2017-05-31
      • 2020-05-13
      • 2023-03-03
      • 2020-12-17
      • 2011-05-24
      相关资源
      最近更新 更多