首页 > 解决方案 > Spring Integration 配置文件中的环境特定 url

问题描述

我正在寻找是否可以为不同的环境动态配置 -

  1. API 密钥
  2. 网关 URL

<int:chain input-channel="reportInChannel" 
   output-channel="headerFilterChannel"> 
    <int:header-enricher>           
        <int:header name="Api-Key" value="B82853E8B"></int:header>      
    </int:header-enricher>
    <int-http:outbound-gateway  
                          url="https://shh.str1.tst.bl/ia-zadmin/rest/sign/v2/{signalId}"
                          http-method="GET"                
                          header-mapper="headerMapper" 
                          expected-response-type="java.lang.String"
                          encode-uri="false" request-factory="sslFactory">             
                    <int-http:uri-variable name="signalId" expression="payload" />
    </int-http:outbound-gateway>
    <int:object-to-string-transformer></int:object-to-string-transformer>
</int:chain>

编辑1:

@SpringBootApplication
@EnableIntegration
@PropertySource("classpath:/application.properties")
@ImportResource({"classpath:/common.xml","classpath:/so-on-config.xml"})
@EnableJms
@EnableSwagger2c
public class SpringIntegrationMQApplication {

private QueueConnectionFactory jmsConFactory;

public static void main(String[] args) {
    ConfigurableApplicationContext context = SpringApplication.run(SpringIntegrationMQApplication.class, args);
}

@Bean
public Docket api() { 
    return new Docket(DocumentationType.SWAGGER_2)  
      .select()                                  
      .apis(RequestHandlerSelectors.any())              
      .paths(PathSelectors.any())                          
      .build();                                           
}

 @Bean
 public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
    return new PropertySourcesPlaceholderConfigurer();
 }

}

我的配置 xml 中的占位符没有被替换。我也希望能够使用配置文件 [application-test.properties] 等。谢谢

标签: spring-integration

解决方案


您可以在属性中使用属性占位符。所以,你B82853E8B可以用类似的东西代替:

 <int:header name="Api-Key" value="${my.api.key}">

urlin<int-http:outbound-gateway 也可以作为对一些外部配置属性的引用:

 url="${my.http.url}"

推荐阅读