骆驼配置文件无法读取MacOS中的环境变量

时间:2019-06-21 11:59:01

标签: macos spring-boot spring-mvc apache-camel spring-camel

我有一个Apache camel应用程序,其中camel-config文件中有一个占位符。如果设置我的环境变量,它在Windows机器中可以很好地运行。但这在Mac中不起作用

这是针对具有apache camel版本2.16和spring 4的Java中间件应用程序。我试图在.bash_profile中包括环境变量。当我执行printenv时,显示的值对应于键

这是我的camel-config.xml中的占位符

<bean id = "ICM_HIERARCHY_PROCESSOR" class="p4p.processors.ICMHierarchyProcessor"/>
<bean id = "ICM_PAYMENT_FILE_PROCESSOR" class="p4p.processors.ICMPaymentFileProcessor"/>
<bean id = "INCENTIVE_PROCESSOR" class="p4p.processors.PerformanceProcessor"/>
<bean id = "EMAIL_ALERT_PROCESSOR" class="p4p.processors.EmailAlertProcessor" />
<bean id = "ADM_PROCESSOR" class="p4p.processors.ADMProcessor"/>
<bean id = "ADP_PROCESSOR" class="p4p.processors.ADPProcessor"/>
<bean id = "ADP_CONTROL_PROCESSOR" class="p4p.processors.ADPControlProcessor"/>
<bean id = "HR_PROCESSOR" class="p4p.processors.HRProcessor"/>

<context:property-placeholder location="classpath*:application-${EPAAS_ENV}.properties" ignore-unresolvable="true" order="0"/>

<bean id="loginInfo" class="java.util.HashMap">
    <constructor-arg>
        <map key-type="java.lang.String" value-type="java.lang.String">
            <entry key = "username" value="${p4p.admin.username}"/>
            <entry key = "password" value="${p4p.admin.password}"/>
            <entry key = "encryptKey" value="${p4p.juice.key}"/>
        </map>
    </constructor-arg>
</bean>

application.properties文件:

camel.springboot.name = p4p-central-dispatch-camel

# properties used in the Camel route and beans
# --------------------------------------------

p4p.envName = ${EPAAS_ENV}

使用文件的示例:

@Component
public class EmailAlertProcessor implements Processor {

    @Value("${p4p.envName}")
    private String envString;

    @Override
    public void process(Exchange exchange) throws Exception {
        String fileName = exchange.getIn().getHeader("CamelFileName", String.class);

        exchange.getIn().setHeader("subject", "[ePaaS:POA] File Uploaded from " + envString);
        exchange.getIn().setBody("[ePaaS]File Uploaded: " + fileName + "\nUpload Time:" + new Date());
    }
}

启动服务器时出现此错误

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'JAVA_HOME' in string value "classpath*:application-${EPAAS_ENV}.properties"
    at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:174) [spring-core-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) [spring-core-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:204) [spring-core-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:178) [spring-core-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer$2.resolveStringValue(PropertySourcesPlaceholderConfigurer.java:172) [spring-context-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:282) [spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:209) [spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitArray(BeanDefinitionVisitor.java:217) [spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:189) [spring-beans-4.2.7.RELEASE.jar:4.2.7.RELEASE]
    at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:141) [spring-beans-4.2.7

但是epaas_env的值为E1,它在执行命令printenv后正在打印

0 个答案:

没有答案