【发布时间】:2019-04-09 15:11:04
【问题描述】:
我使用 mySQL 数据库创建了 restfull spring 应用程序。 MyApp 在 Intellij 中运行良好,我使用 intellij 中的构建工件构建 jar。当我运行 jar (java -jar) 时出现错误。
org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”的bean时出错:通过构造函数参数0表示的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class] 中定义名称为“dataSource”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [com.zaxxer.hikari.HikariDataSource]:
这是我的 application.properties
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/TestApp?useSSL=false
spring.datasource.username=root
spring.datasource.password=password
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.example 我的应用 1.0-快照 罐子
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
谁能帮忙?谢谢
【问题讨论】:
-
你是如何建立一个罐子的? mvn 构建命令?
-
@sankar 在 intellij 中构建工件
-
"mvn clean build" 在你的终端窗口上试试这个。它将构建一个带有依赖项的 jar 并使用该 jar
-
mvn package is right command for spring boot 在你的终端上试试这个
-
@MehdiBenmesssaoud 我试过了。运行良好