【发布时间】:2019-10-04 22:28:44
【问题描述】:
我正在使用 Spring Boot 2.1.5.RELEASE 构建多项目。
我在https://github.com/MBurchard/ACME分享了一个例子
从 storage 子项目运行测试用例时,会找到并使用 storage 项目内部的所有 YAML 配置。
当使用配置文件 dev 从 web 项目运行 SpringBootApplication 时,它会显示错误。
spring:
# PROFILES
profiles:
active: ${profile:dev}
错误原因
Caused by: java.lang.IllegalArgumentException: Not a managed type: class de.mbur.acme.User
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:552) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:74) ~[spring-data-jpa-2.1.8.RELEASE.jar:2.1.8.RELEASE]
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66) ~[spring-data-jpa-2.1.8.RELEASE.jar:2.1.8.RELEASE]
原因很清楚。它不使用存储项目中的 application.yml。
切换到 dev-full-config 时,everythink 工作正常
spring:
# PROFILES
profiles:
active: ${profile:dev-full-config}
但我不想为或多或少是内部的数据库重复完整的配置。
如何在不重复内部数据库配置的情况下完成这项工作?
【问题讨论】:
-
我相信这是可以帮助你的解决方案:stackoverflow.com/questions/30198688/…
-
不,不幸的是它不适用于 yaml 文件。我试图将 application.yml 重命名为 dbproerties.yml,但它不再被找到。系统应该足够智能以在测试期间识别基于配置文件的 yaml,即 dbproperties-MySQL-Test.yml
-
我厌倦了将存储项目中的application.yml转换为属性文件,没有运气。
spring.jpa.mapping-resources=hbm/user.xml导致Caused by: java.lang.IllegalArgumentException: Not a managed type: class de.mbur.acme.User
标签: java spring-boot spring-data-jpa