【发布时间】:2021-12-31 23:20:53
【问题描述】:
我正在使用 springboot 和 JPA,但在通过 maven 测试时遇到问题。当我从 IDE 运行时,它们通过了。
问题与日期有关。我在 resources/data.sql 中有此插入:
插入订单(order_id、number、client_id、created_on) 值 (2, '0002', 1, '2021-11-21 16:12:20.414');
但是当我恢复 order_id = 2 时,created_on 日期为空
这仅在我使用 mvn install 运行时发生,直接从 IDE 运行测试已正确设置日期。
pom 依赖:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.5.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
有什么想法吗?
谢谢
【问题讨论】:
-
首先我看到您已经手动定义了休眠等版本,这在 Spring Boot 项目中通常是错误的方式......让 Spring Boot 定义您正在使用的版本。此外,您已将 junit 定义为依赖项,但尚未将 junit 的范围定义为测试...我还建议使用更新版本的 spring boot (2.6.0) 而不是旧版本..这是 EoL
标签: java spring-boot maven unit-testing junit