首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我必须在maven项目中为sql db定义驱动程序?

为什么我必须在maven项目中为sql db定义驱动程序?
EN

Stack Overflow用户
提问于 2018-03-19 13:23:04
回答 1查看 140关注 0票数 1

我遇到了问题,当我设置maven项目时,我创建了springboot应用程序,它连接到postgres db,因此我需要一个驱动程序,因此我已经用3种不同的方式在maven依赖项中指定了它:

  1. org.postgresql postgresql运行时
  2. postgresql postgresql 9.1-901-1.jdbc 4
  3. org.postgresql postgresql 42.2.1

它们都不起作用,所以我不得不在STS(eclipse)中按项目属性指定它,方法是转到project -> build path -> libaries ->添加外部jar。

并将路径设置为在postgres jdcb jar文件之前下载,尽管它已经在maven依赖项中指定,因为我在pom.xml中留下了第一次postgres依赖项声明,所以现在驱动程序在Maven dependency和参考库中定义,现在它正在工作,我没有看到错误:

无法加载驱动程序类: org.postgresql.Driver

但是,我在另一台pc上下载了这个项目,在那里我不需要手动指定一个驱动程序,maven就完成了这个工作。有人知道怎么回事吗?

EN

回答 1

Stack Overflow用户

发布于 2018-03-19 14:55:56

您正在使用SpringBoot maven插件吗?它应该将所有需要的罐子添加到类路径中。对于postgres,您应该只需要这两个依赖项:

代码语言:javascript
复制
<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/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49364067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档