我遇到了问题,当我设置maven项目时,我创建了springboot应用程序,它连接到postgres db,因此我需要一个驱动程序,因此我已经用3种不同的方式在maven依赖项中指定了它:
它们都不起作用,所以我不得不在STS(eclipse)中按项目属性指定它,方法是转到project -> build path -> libaries ->添加外部jar。
并将路径设置为在postgres jdcb jar文件之前下载,尽管它已经在maven依赖项中指定,因为我在pom.xml中留下了第一次postgres依赖项声明,所以现在驱动程序在Maven dependency和参考库中定义,现在它正在工作,我没有看到错误:
无法加载驱动程序类: org.postgresql.Driver
但是,我在另一台pc上下载了这个项目,在那里我不需要手动指定一个驱动程序,maven就完成了这个工作。有人知道怎么回事吗?
发布于 2018-03-19 14:55:56
您正在使用SpringBoot maven插件吗?它应该将所有需要的罐子添加到类路径中。对于postgres,您应该只需要这两个依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>你可以在这里找到一个样本:https://spring.io/guides/gs/relational-data-access/
https://stackoverflow.com/questions/49364067
复制相似问题