Java Mule占位符文档错误?
我希望使用正确的属性方式在多个环境中部署。。。但这个例子不起作用: 网址: 我创建了一个配置了http的项目,如示例中所示:Java Mule占位符文档错误?,java,spring,deployment,mule,placeholder,Java,Spring,Deployment,Mule,Placeholder,我希望使用正确的属性方式在多个环境中部署。。。但这个例子不起作用: 网址: 我创建了一个配置了http的项目,如示例中所示: <http:listener-config name="HttpListenerConfiguration" doc:name="HTTP Listener Configuration" host="${mule.env.host}" port="
<http:listener-config name="HttpListenerConfiguration"
doc:name="HTTP Listener Configuration"
host="${mule.env.host}"
port="${mule.env.port}"
basePath="${mule.env.basePath}" />
dev.basePath=test/products
dev.host=localhost
dev.port=8082
prod.basePath=products
prod.host=www.acme.com
prod.port=8081
<context:property-placeholder location="config.properties"/>
mule.env=dev
并设置占位符:
<http:listener-config name="HttpListenerConfiguration"
doc:name="HTTP Listener Configuration"
host="${mule.env.host}"
port="${mule.env.port}"
basePath="${mule.env.basePath}" />
dev.basePath=test/products
dev.host=localhost
dev.port=8082
prod.basePath=products
prod.host=www.acme.com
prod.port=8081
<context:property-placeholder location="config.properties"/>
mule.env=dev
当我以以下方式运行它时:
[Could not resolve placeholder 'mule.env.host' in string value "<http:listener-config name="ejemplop....]
host属性可以工作,但是如果我对端口执行相同的操作
(${${mule.env}.port}
给我一个错误
[..${${mule.env}.port}' is not a valid value of union type 'substitutableInt'....]
但如果我在属性文件中添加
env.port=${${mule.env}.port}
并将连接器更改为:
<http:listener-config name="HttpListenerConfiguration"
doc:name="HTTP Listener Configuration"
host="${${mule.env}.host}"
port="${env.port}"
basePath="${mule.env.basePath}" />
这很有效。
有一种奇特或恰当的方法可以做到这一点吗?我认为出于实际目的,你可以忽略对春天的提及。在封面下,我认为全球占位符使用了这种技术。以下是一些对我有用的简单步骤:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd">
<context:property-placeholder location="${mule.env}.properties"/>
<http:listener-config name="HTTP_Listener_Configuration" host="${mule.env.host}" port="${mule.env.port}" doc:name="HTTP Listener Configuration"/>
<http:request-config name="HTTP_Request_Configuration" host="jsonplaceholder.typicode.com" port="80" doc:name="HTTP Request Configuration"/>
<flow name="myprojectFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<http:request config-ref="HTTP_Request_Configuration" path="/users" method="GET" doc:name="HTTP"/>
</flow>
</mule>
CHo,您正朝着多环境的方向前进,但还没有完全实现。如果您需要多个属性文件,每个文件都有相同的属性,具有相同的名称,但具有特定于环境的值,那么我将给出建议 在您的应用程序中,您的
<context:property-placeholder location="config_${mule.env}.properties"/>
您将拥有另一个名为config_prod.properties的属性文件,其中包含:
basePath=products
host=www.acme.com
port=8081
当mule.env设置为dev时,将使用config_dev值。当设置为prod时,将使用config_prod值。Ty非常多,这就是我现在在其他项目中使用它的方式。我的错误是认为“spring或Mule”将在${Mule.env.host}中仅替换“${Mule.env”部分,这就是我现在在其他项目中使用它的方式。我的错误是认为“spring或Mule”将在${Mule.env.host}中仅替换“${Mule.env” part@CHo没问题。您尝试的问题是解码需要多次传递,并且可能需要不同的语法来告诉VM按什么顺序进行操作。即使是有效的方法也需要多次传递,但逻辑足够简单,解释器可以解码并首先执行占位符替换,而不是您尝试的嵌套替换。在处理此类问题时,请记住一件事,mule vs.spring:mule是基于spring构建的。mule与mule可能有一些细微的语法差异,但它正在实现spring上下文。