不使用Spring Boot创建Spring Cloud Config Server

8
我查看了 spring-cloud-config client without Spring Boot 和许多其他问题,但都没有找到令人信服的答案。所以问题来了:
问题: 在Spring应用程序中,是否可以在不使用Spring Boot的自动配置的情况下使用Spring Cloud Config服务器/客户端?使用Spring Boot是使用这些框架的要求吗?
如果是: 1. 是否有任何明确描述启用Spring Cloud Config服务器/客户端而不使用Spring Boot所需完成的工作的文档? 2. 是否有任何清晰地描述启用Spring Cloud Config服务器/客户端而不使用Spring Boot所需完成的工作的示例项目?

是的,您可以在不引导的情况下使用它。没有文档或示例存在。 - spencergibb
如果不使用引导程序,使用它的一般步骤是什么?如果您能提供一些提示,我很乐意自己解决。谢谢。 - Misagh Moayyed
1个回答

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>

您需要确保在Java命令行中传递-Dspring.profiles.active=current_profile参数,就像您可能已经在使用Spring Boot时所做的那样。


谢谢您的评论,这很有帮助。 - Misagh Moayyed
2
有人能添加一个带源代码的示例应用程序吗?您可以按以下方式指定URL:${spring.cloud.config.uri}/${spring.application.name}-${spring.profiles.active}.properties。这样,您以后可以轻松迁移到Spring Cloud。 - Marcello DeSales

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接