java 运行 jar 时无法确定数据库类型 NONE 的嵌入式数据库驱动程序类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45371804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:40:06  来源:igfitidea点击:

Cannot determine embedded database driver class for database type NONE while running jar

javaspring-bootintellij-ideajardatasource

提问by Anas

As mentioned in the headline of question I am facing issue Cannot determine embedded database driver class for database type NONE. The application I have built is on spring boot and working fine when I run the code in intellij.

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

I have followed several questions regarding the same exception and they suggested that I need to add spring.datasourceproperties in my application.properties file. I already have them and still facing the same issue. This issue occurs when I create jar file using artifacts of intellij and then run it by the following command. java - jar myJar.jar

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

My application.properties file

我的 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

Error Log while running jar

运行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).

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).

采纳答案by Jarri Abidi

You should create the jar from maven, to do that go to Viewon top then Tool Windows/Maven Projectsand from there double click on install in LifeCycleoption in maven. Use the jar created by that command instead of using intellij. It Should work.

您应该从 maven 创建 jar,为此转到顶部的查看,然后是工具 Windows/Maven 项目,然后双击maven中的生命周期选项中的安装。使用该命令创建的 jar 而不是使用 intellij。它应该工作。