How to configure dynamic properties while using spring boot?

被刻印的时光 ゝ 提交于 2019-11-30 08:24:53

If you are using Spring boot have a look on @ConfigurationProperties. You will be required to provide a Bean to access your properties. Therefore original values of the properties can be changed during execution since they are regular properties of a bean.

In your case for example:

@Component
@ConfigurationProperties
public class JmsProperties {

    private String url = "vm://localhost" (let's suppose you use ActiveMQ);

    public String getUrl()...
    public void setUrl(String value)...

}

And then inject this bean in you JMS message listener.

Of course if you use JMS and Spring boot, with autoconfiguration you already have Properties class...

Your requirement is a good use-case for "Spring Cloud Config" where not only you can have your all configurations centrally located but also can refresh them dynamically and which in turn can be picked by your referencing app from the very next moment. Refer this standard spring link for same.

You might want to take a look at Togglz: www.togglz.org

From their homepage:

Togglz is an implementation of the Feature Toggles pattern for Java. Feature Toggles are a very common agile development practices in the context of continuous deployment and delivery. The basic idea is to associate a toggle with each new feature you are working on. This allows you to enable or disable these features at application runtime, even for individual users.

Togglz is not bound to the spring framework but supports it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!