简体   繁体   English

Spring Boot - 在运行时或编译时有条件地加载模块

[英]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.

相关问题 在运行时或编译时评估/解析左右对象? - left and right objects are evaluated / resolved during runtime or compile-time? 在新的简单Spring Boot项目中未找到@Aspect(编译时) - @Aspect not found (compile-time) in new, simple Spring Boot Project 在编译时有条件地删除Java方法 - Conditionally Remove Java Methods at Compile-Time 编译时错误或运行时错误 - Compile-time error or runtime error 对运行时批注执行编译时检查 - enforcing compile-time checking on runtime annotation 用于区分运行时类型和编译时类型的 Java 术语 - Java terminology for differentiating runtime type from compile-time type 当 JVM 进程的编译时间结束和运行时间开始时 - when compile-time ends and runtime starts for the JVM process WebDriver driver = new FirefoxDriver()是编译时绑定还是运行时绑定? - WebDriver driver=new FirefoxDriver() is this compile-time or runtime binding? XMLAdapter上的编译时和加载时编织和自动装配不起作用 - Compile-Time and Load-Time Weaving and Autowired on XMLAdapter not working Java Spring —在编译时识别语法错误(在Eclipse中) - Java Spring — identify syntax errors at compile-time (in Eclipse)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM