java - Spring 启动: only discover JPA entity in test profile

标签 java spring hibernate jpa spring-boot

我想要一个仅用于测试的@Entity。这是因为我想测试 @MappedSupertype 而不创建对扩展它的真实实体的依赖关系。

源文件位于 src/test/java 中,但在 Eclipse 中运行应用程序时,会发现该实体(例如,在架构导出上创建一个表)。是否有类似 @Profile("test") 的东西,我可以在应用程序外部(即在测试源中)配置实体?

最佳答案

放置你的实体src/test/java,它自然不会在生产中注册到Hibernate中,因为测试文件夹对生产类不可见

关于java - Spring 启动: only discover JPA entity in test profile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45712718/

相关文章:

java - 在 Spring Boot Data REST 中进行实体验证后运行 @HandleBeforeCreate

java - 使用多个 ManyToOne 连接进行查询

java - Hibernate 标准 - 加入未映射的实体

java - Spring 3.1 和 Hibernate 4 : "HibernateException: No Session found for current thread" When calling DAO method from unit test

Java、谷歌集合库; AbstractIterator 的问题?

使用 ObjectMapper 将 POJO 转换为 HashMap<String,String> 时出现 java.lang.String out of START_ARRAY 错误

java - 在终止的代码上使用 JUnit

java - Spring MVC + Stomp + WebSocket + https 不作为 http

找不到 Spring 数据 jpa 存储库属性

java - 建议将递归 Diff 算法转换为迭代算法?