动态配置 spring 的集成 int-http:inbound-gateway

Dynamically configuring spring's integration int-http:inbound-gateway

目前我有一个简单的 war,其中包含一些 spring 集成配置,并且此 war 使用以下代码部署到码头容器中:

protected void createWac(File file, ConnectorConfig config) throws Exception, InterruptedException {
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar(file.getAbsolutePath());
    startServer(webapp, inboundConnector.getPort());
}

在 Spring 集成配置中,我有一个像这样的 int-http:inbound-gateway

<!-- External listener definition -->
<int-http:inbound-gateway id="entryHttpInboundGateway"
    request-channel="myRequestChannel"
    path="myPath" 
    reply-channel="myReplyChannel"
    request-payload-type="com.me.MyType"
    supported-methods="POST" message-converters="converters"
    reply-timeout="1000">
</int-http:inbound-gateway>

我的目标是动态设置 myPath 的值和支持的方法值,我采用的第一种方法是在我的 xml 文件中添加变量,正如一些人建议的那样 post: how to read System environment variable in Spring applicationContext

为此,我尝试使用此配置

<!-- External listener definition -->
<int-http:inbound-gateway id="entryHttpInboundGateway"
    request-channel="myRequestChannel"
    path="#{ systemProperties['HTTP_PATH'] }" 
    reply-channel="myReplyChannel"
    request-payload-type="com.me.MyType"
    supported-methods="POST" message-converters="converters"
    reply-timeout="1000">
</int-http:inbound-gateway>

并在我的机器上设置 env,奇怪的是,当我设置它时,没有任何反应,也没有配置错误、通道初始化或找不到 属性,我知道,因为如果我删除 # 符号,或者将实际的 url 放在控制台上,我会得到这个:

IntegrationRequestMappingHandlerMapping - Mapped "{[/{ systemProperties['HTTP_PATH'] }],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException

关于如何解决这个问题的任何想法,或者在部署到码头容器之前能够将值注入 war 的上下文文件的其他方法?

您必须查看 Spring 中的 Environment Abstractionhttp://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-environment

并考虑在 PropertySourcesPlaceholderConfigurer 的情况下为您的应用程序设置一些挂钩,并且在 ServletConfig 的情况下看起来像:

For a common StandardServletEnvironment, the full hierarchy looks as follows, with the highest-precedence entries at the top: * ServletConfig parameters (if applicable, e.g. in case of a DispatcherServlet context) * ServletContext parameters (web.xml context-param entries) * JNDI environment variables ("java:comp/env/" entries) * JVM system properties ("-D" command-line arguments) * JVM system environment (operating system environment variables)

从其他方面考虑迁移到 Spring Boot