Ary*_*rya 4 postgresql spring-boot
我正在使用 Spring boot 2.1.5.RELEASE 并且在我的 pom.xml 中有以下依赖项
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
但是org.postgresql.util.PGobject没有找到。在另一个非 spring 启动项目中,我有以下依赖项
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
并且org.postgresql.util.PGobject可以使用。
知道为什么org.postgresql.util.PGobject在 spring boot 项目中找不到吗?
因为您Postgresql在runtime作用域中设置了JDBC 驱动程序,它具有以下行为:
此范围表示该依赖项不是编译所必需的,而是执行所必需的。它在运行时和测试类路径中,但不在编译类路径中。
它不在编译类路径中,导致在编译期间找不到它的类。您应该将其更改为compilescope ,这是默认范围,因此您可以简单地省略<scope>:
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1007 次 |
| 最近记录: |