【问题标题】:spring-boot application.properties maven multi-module setupspring-boot application.properties maven 多模块设置
【发布时间】:2015-11-03 14:13:45
【问题描述】:

我正在为 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 而不将依赖模块安装到本地存储库吗?

提前致谢

【问题讨论】:

    标签: java maven spring-boot


    【解决方案1】:

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

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

    【讨论】:

    • 没错,我可以将属性用作配置文件。但这不起作用 application-infrastructure.properties 没有加载我猜。我在github上更新了项目。
    • 我运行了您的应用程序并加载了基础架构配置文件。所以我不知道你的问题是什么。顺便说一句,您的 Web 项目中没有 ServletInitializer,因此您不可能正确部署该战争。检查spring.io/guides/gs/convert-jar-to-war
    • 问题是 h2 db 应该在文件夹 ~/h2db/ 中创建,但它不存在,所以我敢打赌 application-infrastructure.properties 未加载或加载不正确。
    • 它在我身边(-rw-r--r-- 1 snicoll 员工 208896 Aug 12 16:16 /Users/snicoll/h2db/axonpoc.mv.db)。无论如何,有更好的方法来确定配置文件是否已加载(例如执行器)。
    • 这很奇怪,它对我不起作用 - 我看不到那个 db 文件,即使我尝试更改基础设施中的服务器端口。属性它不会改变。您是否更改了我的测试项目中的任何内容以使其正常工作?
    猜你喜欢
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2015-10-10
    • 2014-11-12
    • 2016-08-28
    • 2016-04-28
    相关资源
    最近更新 更多