没有Spring Boot的Spring Cloud Config Server

Mis*_*yed 6 spring spring-boot spring-cloud

我看过没有Spring Boot的spring-cloud-config客户端和许多其他客户端,并没有找到令人信服的答案.所以这里再说一遍:

问题:在Spring应用程序中,是否有可能在没有Spring Boot自动配置的情况下使用Spring Cloud Config服务器/客户端?使用Spring Boot是否需要使用这些框架?

如果是:

  1. 是否有任何文档清楚地描述了为了在没有Spring Boot的情况下启用Spring Cloud Config服务器/客户端需要做什么?
  2. 是否有任何示例项目清楚地描述了为了在没有Spring Boot的情况下启用Spring Cloud Config服务器/客户端需要执行哪些操作?

Ami*_*ein 4

我不知道文档或示例项目。然而,我们正在我们的项目中这样做。

您只需包含配置服务器 URI 作为属性源(假设您使用的是 PropertySourcesPlaceholderConfigurer):

<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer" id="propertyPlaceholder">
    <property name="locations">
        <list>
            <value>http://your-config-server.com:8888/application-${spring.profiles.active}.properties</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="false"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

您必须确保将 -Dspring.profiles.active=current_profile 传递到 java 命令行,就像您可能对 boot 所做的那样。

  • 有人可以添加带有源代码的示例应用程序吗?您可以按如下方式指定 URL:`${spring.cloud.config.uri}/${spring.application.name}-${spring.profiles.active}.properties`。这样,您以后就可以轻松迁移到 Spring Cloud。 (2认同)