简体   繁体   English

是否可以在运行时在Spring Boot中更改property.file中的特定值?

[英]Is it possible to change at runtime a specific value inside a property.file in spring boot?

I'm developing an API which will connect with several endpoints. 我正在开发将与多个端点连接的API。 The uri for each endpoint is something like this: 每个端点的uri如下所示:

rest/services/General/directory1/MapServer/export
rest/services/General/directory2/MapServer/export
rest/services/General/directory3/MapServer/export
rest/services/General/directory4/MapServer/export

and so on... 等等...

I don't know if it's possible, but would like to have something like this instead: 我不知道是否可能,但想改成这样:

rest/services/General/${value}/MapServer/export

and then on my code just call the endpoint above injecting the specific directory that I want on ${value} 然后在我的代码上调用上面的端点,将我想要的特定目录注入$ {value}上

Is it possible? 可能吗? Don't know what I'm missing as I googled but couldn't find anything related. 搜寻Google时不知道我想念的东西,但找不到任何相关的东西。

Cheers 干杯

You can do so by means of Spring Cloud Config. 您可以通过Spring Cloud Config来实现。

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持。 With the Config Server you have a central place to manage external properties for applications across all environments. 使用Config Server,您可以集中管理所有环境中应用程序的外部属性。 The concepts on both client and server map identically to the Spring Environment and PropertySource abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. 客户端和服务器上的概念与Spring Environment和PropertySource抽象完全相同,因此它们非常适合Spring应用程序,但可以与以任何语言运行的任何应用程序一起使用。 As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. 当应用程序从开发人员迁移到测试人员并进入生产过程时,您可以管理这些环境之间的配置,并确保应用程序具有在迁移时需要运行的所有内容。 The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. 服务器存储后端的默认实现使用git,因此它轻松支持配置环境的标记版本,并且可以由各种工具访问以管理内容。 It is easy to add alternative implementations and plug them in with Spring configuration. 添加替代实现并将其插入Spring配置很容易。

For more details, kindly go through spring documentation here . 有关更多详细信息,请在此处阅读spring文档。

I solve the problem using the simplest approach possible. 我使用最简单的方法来解决问题。 In my code I used the string.replace() method. 在我的代码中,我使用了string.replace()方法。 Was looking for something more robust, but as it was taking lots of time to sort it out how to do it, I decided to go with the string.replace method. 我一直在寻找更可靠的方法,但是由于要花很多时间来整理方法,所以我决定使用string.replace方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM