简体   繁体   English

Spring cloud config - 加载其他文件

[英]Spring cloud config - loading additional files

I got a spring cloud server for my applications, serving the common property files at startup. 我为我的应用程序安装了一个spring cloud服务器,在启动时提供公共属性文件。

The 'normal' functionality is working fine. “正常”功能正常运行。 An application fetches the hierarchy of files and got the full access to the loaded parameters. 应用程序获取文件层次结构并获得对加载参数的完全访问权限。

Application.properties
Application-<profile>.properties
<applicationname>.properties
...

Now the question: How can I load a configuration file beside the common naming? 现在的问题是:如何在通用命名旁边加载配置文件?

If I am storing another file in repositoy eg sharedCommonServers.properties, how can I load this file in addition using the config server? 如果我在repositoy中存储另一个文件,例如sharedCommonServers.properties,如何使用配置服务器另外加载此文件? This file contains properties used by some but not all programs. 此文件包含某些但不是所有程序使用的属性。

Thank you in advance! 先感谢您!

Hendrik 亨德里克

Ok, at least I found a solution: 好的,至少我找到了一个解决方案:

I took the normal application-context of cloud config. 我采用了云配置的正常应用程序上下文。 Within this context I placed my file sharedCommonServers.properties as a default application property file with a special profile. 在此上下文中,我将文件sharedCommonServers.properties作为具有特殊配置文件的默认应用程序属性文件。

Renaming: 重命名:

'sharedCommonServers.properties' to 'application-commonServers.properties'

By extending the profile settings with 'commonServers' spring cloud config is fetching it in addition. 通过使用'commonServers'扩展配置文件设置,spring cloud配置另外提取它。

Take care there are no overlapping property-keys in the other profile-line. 请注意,其他配置文件行中没有重叠的属性键。

So in my environment when I set... 所以在我的环境中,当我设置...

-Dspring.profiles.active=prod,commonServers' 

...I get my default prod configuration and those marked as 'commonServers' profiles. ...我得到了我的默认prod配置和那些标记为'commonServers'的配置文件。

application.properties
application-prod.properties
application-commonServers.properties // the additional one
<appname>.properties
<appname>-prod.properties
// and <appname>-commonServers.properties if I would need it

Thank you for your suggestions and thoughts! 感谢您的建议和想法!

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

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