【问题标题】:Getting a non Spring Boot program such as ActiveMQ to work with Spring Cloud Config让 ActiveMQ 等非 Spring Boot 程序与 Spring Cloud Config 一起使用
【发布时间】:2015-12-08 02:40:49
【问题描述】:

我稍微修改了我原来的问题,以更好地反映我的问题。我有一个非 Spring Boot 应用程序,我想与 Spring Cloud Config Server 一起使用。我在网上搜索并尝试了很多东西,但似乎我的问题的症结在于服务器只能在 Spring Boot 上下文中工作。尽管 ActiveMQ 已经是一个 Spring 应用程序,但将其转换为 Spring Boot 应用程序似乎并非易事。

我想要一个从 Spring Cloud Config 配置的 ActiveMQ Broker。 application.properties 中的本地设置应替换为来自服务器的设置。这适用于我工作的其他服务器,现在我需要它为我的代理过滤器插件工作。

我在activemq.xml中添加了以下内容:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:application.properties</value>
            <value>file:${activemq.conf}/credentials.properties</value>
        </list>
   </property>
</bean>

NOTE: Several base packages omitted here but are similar to:
<context:component-scan base-package="org.springframework.cloud.bootstrap"/>

<!-- enables annotation based configuration -->
<context:annotation-config />

这样做之后,我能够获得各种 @Value 注释来处理来自我的 application.properties 的设置,但整个 Spring Cloud Config Server 似乎并不能取代我的本地 application.properties 文件设置。我工作的其他 Spring Boot 应用程序这样做,所以我知道服务器很好。

我已将以下 jar 添加到 apache-activemq-5.12.0\lib\extra 目录中:

spring-aop-4.1.8.RELEASE.jar
spring-beans-4.1.8.RELEASE.jar
spring-boot-1.2.7.RELEASE.jar
spring-boot-actuator-1.2.7.RELEASE.jar
spring-boot-autoconfigure-1.2.7.RELEASE.jar
spring-boot-starter-1.2.7.RELEASE.jar
spring-boot-starter-actuator-1.2.7.RELEASE.jar
spring-boot-starter-data-mongodb-1.2.7.RELEASE.jar
spring-boot-starter-logging-1.2.7.RELEASE.jar
spring-cloud-commons-1.0.1.RELEASE.jar
spring-cloud-config-client-1.0.1.RELEASE.jar
spring-cloud-context-1.0.1.RELEASE.jar
spring-cloud-starter-1.0.1.RELEASE.jar
spring-cloud-starter-config-1.0.1.RELEASE.jar
spring-context-4.1.8.RELEASE.jar
spring-context-support-4.1.8.RELEASE.jar
spring-core-4.1.8.RELEASE.jar
spring-data-commons-1.11.0.RELEASE.jar
spring-data-mongodb-1.8.0.RELEASE.jar
spring-expression-4.1.8.RELEASE.jar
spring-jms-4.1.8.RELEASE.jar
spring-security-crypto-3.2.8.RELEASE.jar
spring-test-4.1.8.RELEASE.jar
spring-tx-4.1.8.RELEASE.jar
spring-web-4.1.8.RELEASE.jar

【问题讨论】:

  • 为什么会有PropertyPlaceholderConfigurerPropertySourcesPlaceholderConfigurer ?为什么两个都有application.properties
  • 拼命地试图让它发挥作用并且想法重叠。我可能只需要一个,并且可能会在清理过程中移除一个。关于获得一个非 Spring Boot 程序,就像我的情况一样,ActiveMQ 与配置服务器一起工作,你有什么意见吗?
  • 您是否尝试过仅使用 PropertySourcesPlaceholderConfigurer?这是从外部属性文件中读取的文件
  • @jny - 是的。我现在正在尝试使用 org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
  • 这个问题有更新吗?

标签: spring spring-boot activemq


【解决方案1】:

refreshendpoint 不一定在调用构造函数时初始化。您需要使用 @PostConstruct 添加方法注释(或实现 InitializingBean 并实现 afterPropertiesSet 方法),您将在其中执行 refreshendpoint.refresh(); ,例如:

@PostConstruct
void init() {
    refreshendpoint.refresh();
} 

【讨论】:

  • 正确。我现在意识到那个只是为了看看它是否被加载的测试是愚蠢的。替换 application.properties 是我主要关心的问题。我将编辑我的原始帖子以省略这部分问题。不过,我的主要问题仍未得到解答。
猜你喜欢
  • 2021-11-16
  • 2015-10-04
  • 2021-10-09
  • 2017-10-20
  • 2016-06-04
  • 2017-08-31
  • 2015-09-03
  • 2021-03-22
  • 2017-11-28
相关资源
最近更新 更多