[英]Spring Boot - Conditionally load module during runtime or compile-time
First of all, I am new to Spring Boot so I am not sure if something like this is possible within the framework.首先,我是 Spring Boot 的新手,所以我不确定框架内是否可以实现这样的功能。
Let me describe my problem.让我描述一下我的问题。
I have 10 code repositories.我有 10 个代码库。 Each repository listens to a data stream, parses the data and updates a database.
每个存储库侦听数据流,解析数据并更新数据库。 Due to maintainability issues I plan on bringing it under a single code repository.
由于可维护性问题,我计划将其置于单个代码存储库中。 This new application will be generalized, and certain app specific configurations (for example, which stream should I connect to, the database host) will be retrieved at run-time.
这个新应用程序将被通用化,并且某些特定于应用程序的配置(例如,我应该连接到哪个流,数据库主机)将在运行时检索。
Theoretically, this would allow me to maintain a single code base, but deploy it as 10 separate services based on configurations which is what I need.从理论上讲,这将允许我维护一个单一的代码库,但根据我需要的配置将其部署为 10 个独立的服务。 However, there's a set of java classes that are application specific used to parse the retrieved data.
但是,有一组特定于应用程序的 java 类用于解析检索到的数据。 To better understand this refer the diagram below.
为了更好地理解这一点,请参阅下图。
Ideally, I need to still maintain these classes in the same repository, but as separate modules.理想情况下,我仍然需要在同一个存储库中维护这些类,但作为单独的模块。 Once the configurations are loaded, the app should be able to load the corresponding module into the application context and initialize the Java classes.
加载配置后,应用程序应该能够将相应的模块加载到应用程序上下文中并初始化 Java 类。 The other modules will not be used.
不会使用其他模块。
Can I do something like this with Spring Boot?我可以用 Spring Boot 做这样的事情吗? Alternately, even a build time solution is fine if I can create separate builds which can then be deployed separately.
或者,如果我可以创建单独的构建然后可以单独部署,那么即使是构建时解决方案也很好。
Not sure did I understood it well but why don't try spring profile ( https://www.baeldung.com/spring-profiles ).不确定我是否理解它,但为什么不尝试 spring profile ( https://www.baeldung.com/spring-profiles )。 You can set for every service different config and with spring.profiles.active in runtime say what configuration will use.
您可以为每个服务设置不同的配置,并在运行时使用 spring.profiles.active 说明将使用什么配置。
Also something like this could be useful https://www.baeldung.com/spring-reloading-properties像这样的东西也很有用https://www.baeldung.com/spring-reloading-properties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.