gpt4 book ai didi

java - spring-boot application.properties maven 多模块设置

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:04 26 4
gpt4 key购买 nike

我正在为 maven 多模块项目中的 application.properties 设置而苦苦挣扎。我有结构

--parent
----core-api
----infrastructure (infrastructure.properties)
----command
----web (application.properties)

我为 appliaction.properties 使用了不同的名称,因为我想将它们全部加载到目标模块中。

我读过 thisthis帖子所以我决定放

@PropertySource(value = { "classpath:application.properties","classpath:infrastructure.properties" })

web 模块中的 Application.class。但是当我从我的父项目运行命令 mvn spring-boot:run 时,我得到异常:

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.github.bilak.axonframework.poc.Application]; nested exception is java.io.FileNotFoundException: class path resource [infrastructure.properties] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:180)

我的项目可以找到here

  1. 如何在使用 maven 插件时让它工作?有没有办法在 java 中设置它并使用 maven 运行?
  2. 这与 maven 更相关,但我可以从 web 模块运行 mvn spring-boot:run 而无需将依赖模块安装到本地存储库吗?

提前致谢

最佳答案

您可以重用 Spring Boot 基础设施,而不是自己做事。您可以拥有 applications-infrastructure.properties 并启用 infrastructure 配置文件。

关于你的第二个问题,不应该先安装其他模块;您还可以在 #3436 中找到相关讨论

关于java - spring-boot application.properties maven 多模块设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31940317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com