提问
我使用的是
Spring boot 2.1.5.RELEASE 我在我的pom .xml中有以下依赖项
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
但是没有找到。
在另一个非spring boot项目中,我有以下依赖org.postgresql.util.PGobject
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
并且可以使用org.postgresql.util.PGobject
在spring boot项目中找不到原因;org.postgresql.util.PGobject
解答
因为您在运行时作用域中设置了JDBC驱动程序,它具有以下行为: Postgresql
此作用域指示编译时不需要依赖项,但执行时需要依赖项。
它在运行时和测试类路径中,但不在编译类路径中。
它不在编译类路径中,导致在编译期间无法找到它的类。您应该将其更改为scope,这是默认范围,因此您可以简单地省略它:编辑<scope>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
参考:spring boot - org.postgresql.util.PGobject not available in org.postgresql - Stack Overflow