简体   繁体   English

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

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

Currently I have a simple war that holds some spring integration configuration, and this war is deployed into a jetty container using this code:目前我有一个包含一些 spring 集成配置的简单战争,并且使用以下代码将此战争部署到码头容器中:

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

among the Spring Integration config, I have a int-http:inbound-gateway like this在 Spring Integration 配置中,我有一个像这样的 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>

My goal is to have the values for myPath and the supported-methods values set up dynamically, the first approach I went was to have variables on my xml file as some people suggest on this post: how to read System environment variable in Spring applicationContext我的目标是动态设置 myPath 的值和支持的方法值,我采用的第一种方法是在我的 xml 文件中设置变量,正如一些人在这篇文章中所建议的: 如何读取 Spring applicationContext 中的系统环境变量

for that I tried with this config为此,我尝试使用此配置

<!-- 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>

and setting the env on my machine, the weird thing is that when I set this, nothing happens, nor an config error, the initialization of the channel, or a property not found, I know, because if I remove the # sign, or put the actual url I get this on the console:并在我的机器上设置 env,奇怪的是,当我设置它时,没有任何反应,也没有配置错误、通道的初始化或未找到的属性,我知道,因为如果我删除 # 符号,或者把我得到的实际网址放在控制台上:

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

Any ideas on how to solve this, or another approach to be able to inject the values to the war's context file before its deployed into the jetty container?关于如何解决这个问题的任何想法,或者在部署到码头容器之前能够将值注入到战争的上下文文件中的另一种方法?

You have to take a look in to the Environment Abstraction in the Spring: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-environment您必须查看 Spring 中的Environment Abstractionhttp : //docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-environment

And consider some hook for your application in face of PropertySourcesPlaceholderConfigurer and looks like in your case for the ServletConfig :并在面对PropertySourcesPlaceholderConfigurer为您的应用程序考虑一些钩子,并且在您的ServletConfig情况下看起来像:

For a common StandardServletEnvironment, the full hierarchy looks as follows, with the highest-precedence entries at the top: * ServletConfig parameters (if applicable, eg 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)对于常见的 StandardServletEnvironment,完整的层次结构如下所示,最高优先级条目位于顶部: * ServletConfig 参数(如果适用,例如在 DispatcherServlet 上下文的情况下) * ServletContext 参数(web.xml 上下文参数条目)* JNDI 环境变量(“java:comp/env/”条目)* JVM 系统属性(“-D”命令行参数)* JVM 系统环境(操作系统环境变量)

From other side consider to migrate to Spring Boot .从另一方面考虑迁移到Spring Boot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM