首页 > 解决方案 > 自定义实体不会在 Spring Cloud Dataflow Server 中加载

问题描述

一旦我@EnableDataFlowServer我的 SpringBoot 应用程序,我自己的自定义实体就不会加载。(当 JPA 找不到您的实体时,我得到了“类型不受管理”异常)。

这些实体位于我导入的另一个 Spring 模块中,例如

@Import({MyDomainsModule.class})

我正在使用 2.0.0.m2 的 Spring Cloud DataFlow。

我做过的一些调试:

如果我将它添加到我的 Spring Boot 应用程序主类中:

@EntityScan({
"com.company.mydomain.entities"
})

然后我的实体开始像往常一样加载,但随后 Spring DataFlow 中断。例如,每当我尝试加载 UI 时,我都会得到:

 |ne.jdbc.spi.SqlExceptionHelper|  Table 'dataflow.appregistration' doesn't exist 

这让我想通过简单地添加 EntityScan,我打破了一些命名策略,因为表的实际名称当然是app_registration

我认为这主要是“我如何在一个项目中执行基于 JPA 的代码的多个位置”,而不是 Spring Cloud DataFlow 问题。但是要知道修复可能需要更好地了解 SCDF 的原理。我已经检查了该项目并阅读了 Spring Boot 以及 SCDF 如何配置自身。

任何帮助是极大的赞赏!

标签: javaspringspring-bootspring-cloud-dataflow

解决方案


我有一个糟糕的策略来自我的一个属性,覆盖了 SCDF 将它添加到我的 application.properties 中的内容。

所以明确地说,我在我的属性中设置了这个:

spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

然后我的 SpringBoot 应用程序看起来像

@SpringBootApplication(exclude = LocalDataFlowServerAutoConfiguration.class)
@Import({MyDomainModule.class})
@EnableDataFlowServer

// EnableDataFlowServer has an EntityScan, which causes ours to not be picked up!
// Look in DataFlowControllerAutoConfiguration for more information
@EntityScan({
"com.company.mydomain.entities"
})

推荐阅读