【问题标题】:Springboot , tomcat 8 , can't find driver for PostgresSpring Boot,tomcat 8,找不到 Postgres 的驱动程序
【发布时间】:2015-08-09 10:47:02
【问题描述】:

我正在使用带有 Postgres 的 Spring Boot 应用程序。

但是如果不将我的 postgres.jar 添加到 tomcat 的 lib 中,我将无法运行它。

有没有可能只使用我在我的应用程序中添加的 postgres jar。

真的想将我所有的 jar 依赖项隔离到我的战争中,而不是更改我的 Tomcat。

我的理解是它为我的应用程序使用了 tomcat 池,有什么方法可以禁用它吗?

这是我的pom

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-processing</artifactId>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>


       <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-tools-common</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-simple</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4-1201-jdbc41</version>
    </dependency>
</dependencies>

application.properties

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop

【问题讨论】:

  • 请添加您的数据源配置。
  • 我假设您没有将 postgres jar 添加到 maven 依赖项。如果这不是您想要的,请您发布您的 pom 和 jdbc 配置
  • 检查这个示例配置 pom.xml - 添加对 postgresql 驱动程序的依赖项 - github.com/AlgiersJUG/spring-boot-postgres-sample/blob/master/…
  • 我已经添加了我的 pom 依赖项
  • 请您提供完整的POM

标签: java spring tomcat spring-boot tomcat8


【解决方案1】:

您只需在 pom.xml 中添加 postgres.jar 作为依赖项。

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
</dependency>

【讨论】:

  • 虽然这可能是正确的,但 OP 并没有在任何地方指定他使用 maven 作为他的依赖项/构建框架。
  • 我使用 maven,并且我的 pom 中有依赖项,
  • 请从您的 pom.xml 中删除 9.4-1201-jdbc41。 Spring-boot 会自动为你解析版本。虽然我真的怀疑这是否会对你有所帮助。
  • org.springframework.bootspring-boot-dependencies1.2.3.RELEASEpomimport
猜你喜欢
  • 2013-08-31
  • 1970-01-01
  • 1970-01-01
  • 2013-04-22
  • 2022-01-21
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 2019-10-17
相关资源
最近更新 更多