简体   繁体   English

外部化 spring 启动/安全配置

[英]Externalizing spring boot/security configuration

I have multiple microservices that rely on the exact same classes and configuration beans.我有多个依赖于完全相同的类和配置 bean 的微服务。

Is it possible to externalize this configuration to be included as eg module or dependency?是否可以将此配置外部化以包含为例如模块或依赖项?

So that eg if I would want to change the configuration of these classes all other microservices will have this change.因此,例如,如果我想更改这些类的配置,所有其他微服务都将进行此更改。

I think you could clarify your question.我想你可以澄清你的问题。 If you want properties outside the jar, this is possible following what is described here https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files如果您想要 jar 之外的属性,可以按照此处描述的内容 https://docs.spring.io/spring-boot/docs.html-features-9ternal/config/docs/html-features-9. html#boot-features-external-config-application-property-files

If you want to reuse a set of classes, you can create a separate maven module and add it as a dependency in your microservices.如果您想重用一组类,您可以创建一个单独的 maven 模块并将其作为依赖项添加到您的微服务中。

Update #1 (Describing how to create maven module):更新 #1(描述如何创建 maven 模块):

  1. Create the module using this site: https://start.spring.io/使用此站点创建模块: https://start.spring.io/
  2. Move the reusable code to this new module将可重用代码移动到这个新模块
  3. Run mvn clean install运行 mvn 干净安装
  4. Add the module as a dependency in your microservices将模块添加为微服务中的依赖项

You can create a library in the "spring-boot-starter" style.你可以创建一个“spring-boot-starter”风格的库。 Here is how you do it: https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/boot-features-developing-auto-configuration.html这是您的操作方法: https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/boot-features-developing-auto-configuration.ZFC35FDC30D5FC67D236E8A8228

Very short: You will have a spring.factories file where you specify the beans which will be autoconfigured.很短:您将有一个 spring.factories 文件,您可以在其中指定将自动配置的 bean。 I recommend you to create conditional beans in library so you will be able to create your own beans in the project, in case you need something else.我建议您在库中创建条件 bean,这样您就可以在项目中创建自己的 bean,以防您需要其他东西。

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

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