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

标签 java spring file spring-boot properties

我正在开发一个将与多个端点连接的 API。每个端点的 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

等等...

我不知道这是否可能,但希望有这样的东西:

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

然后在我的代码中只需调用上面的端点,注入(inject)我想要的特定目录 ${value}

这可能吗?当我用谷歌搜索但找不到任何相关内容时,不知道我错过了什么。

干杯

最佳答案

您可以通过 Spring Cloud Config 来完成此操作。

Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. 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. 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. It is easy to add alternative implementations and plug them in with Spring configuration.

有关更多详细信息,请参阅 spring 文档 here .

关于java - 是否可以在运行时更改 Spring Boot 中 property.file 内的特定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54033819/

相关文章:

java - 在 Java 中将 Map 从 Class<?> 保存到 Handler 对象的最合适方法是什么?

java - 如何判断 ImageView 在 android 中是否有设置图像?

java - 在 post api 的请求正文中接受数组时处理失败的更好方法?

c - 在 c unix 编程中,只允许在一个进程中使用 open() 打开文件

java - Java 中的 Monitor 和 Synchronized 关键字

java.sql.SQLIntegrityConstraintViolationException : Cannot add or update a child row: a foreign key constraint fails

java - OpenSessionInView 模式

java - 如何理解Spring中的Bean?

php - 通过 PHP 返回图像并使用 AJAX 设置为 src

python - "File not found"tkinter 按钮命令出错