【问题标题】:Cannot determine embedded database driver class for database type NONE while running jar运行 jar 时无法确定数据库类型 NONE 的嵌入式数据库驱动程序类
【发布时间】:2018-01-04 10:10:08
【问题描述】:

如问题标题中所述,我面临问题Cannot determine embedded database driver class for database type NONE。我构建的应用程序是在 spring boot 上运行的,当我在 intellij 中运行代码时工作正常。

我关注了几个关于同一异常的问题,他们建议我需要在 application.properties 文件中添加 spring.datasource 属性。我已经有了它们,但仍然面临同样的问题。当我使用 intellij 的工件创建 jar 文件然后通过以下命令运行它时,会出现此问题。 java - jar myJar.jar

我的 application.properties 文件

# ===============================
# = DATA SOURCE
# ===============================
spring.datasource.url = jdbc:mysql://localhost:3306/db_wssmith?useSSL=false
spring.datasource.username = 
spring.datasource.password = 
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

运行 jar 时的错误日志

ERROR org.springframework.boot.SpringApplication - Application startup failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).

【问题讨论】:

  • 您的application.properties 文件在哪里?
  • 在 intellij 的项目中,它位于 src/main/resources 中,当我使用 winrar 打开它时,它位于 jar 中,它不在其外部文件夹中的任何文件夹中
  • 好的。在创建数据源 bean 期间,spring 首先读取驱动程序类名称属性。当他无法读取数据源属性时会引发此异常。尝试使用mvn spring-boot:run 运行它,确保config 文件夹下没有另一个application.properties 文件(在您的jar 文件之外)。您的项目中是否配置了任何Datasource bean? .你能发布你的pom.xml的内容吗(即使我不认为这可能是问题)
  • 试图用 mvn spring boot 命令运行它,我不明白 config 文件夹的部分...我没有任何这样的文件夹来替换我的 jar
  • 如果您使用 maven 命令而不是使用 intellij 构建 jar,那么 java -jar yourjar.jar 是否有效?只是为了确保这与 intellij maven conf 相关联。

标签: java spring-boot intellij-idea jar datasource


【解决方案1】:

您应该从 maven 创建 jar,为此转到顶部的 View 然后 Tool Windows/Maven Projects 并从那里双击安装在 maven 中的 LifeCycle 选项。使用该命令创建的 jar,而不是使用 intellij。它 应该可以。

【讨论】:

    猜你喜欢
    • 2018-06-18
    • 2016-02-16
    • 2019-04-09
    • 2014-07-27
    • 2018-02-12
    • 2018-07-10
    • 2018-03-28
    • 1970-01-01
    相关资源
    最近更新 更多