配置选项

Spring Cloud Stream 支持通用配置选项以及用于绑定和绑定程序的配置。某些绑定程序使附加绑定属性支持特定于中间件的功能。spring-doc.cadn.net.cn

配置选项可以通过任何Spring Boot支持的机制提供给Spring Cloud Stream应用程序。这包括应用程序参数、环境变量,以及YAML或.properties文件。spring-doc.cadn.net.cn

<p><strong>Note on using Spring/Boot core property annotations.</strong></p>

无论您处理的是常规属性还是绑定器/绑定器特定属性,有时可能都需要依赖核心 Spring 和 Boot 核心属性注释,例如 @Value@ConditionalOnProperty。对于这些情况,请确保指定属性的完整名称。 例如,给定当前 application.yaml 文件…spring-doc.cadn.net.cn

my:
  prop: foo
spring:
  application:
    name: "messaging-test"
  cloud:
    function:
      definition: "produce;consume"
    stream:
      binders:
        rabbit:
          environment:
            my:
              prop: bar

如果要使用@Value注解注入根my.prop的值,您使用(@Value("${my.prop}") String someProperty)。如果您想要特定于绑定器上下文的那一个,那么您将指定 完整的属性名称3
相同的道理也适用于@ConditionalOnProperty,您将有效地执行同样的操作。
spring-doc.cadn.net.cn