2017-07-28 54 views
0

正如我现在面临的问题Cannot determine embedded database driver class for database type NONE问题的标题提及。我建立的应用程序是在spring引导时运行的,当我在intellij中运行代码时工作正常。无法确定数据库类型无嵌入式数据库驱动程序类,同时运行的jar

我按照有关同一异常的几个问题,他们建议我需要在我的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).

+0

哪里是你的'application.properties'文件在什么位置?在intellij项目中的 –

+1

它是在src/main/resources中,当我用winrar打开它时,它不在任何文件夹中,它的外部文件夹中的 – Anas

+0

ok。在数据源bean创建期间,spring将通过读取驱动程序类名称属性开始。当他无法读取数据源属性时,会抛出此异常。尝试使用'mvn spring-boot:run'运行它,确保你没有在'config'文件夹下有另一个'application.properties'文件(你的jar文件之外)。你有没有配置任何Datasource bean项目? 。你可以发布你的'pom.xml'的内容(即使我不认为这可能是问题) –

回答

2

你应该从行家创建罐子,要做到这一点去查看顶部然后工具的Windows/Maven项目,并从那里双击安装在maven中的LifeCycle选项。使用由该命令创建的jar而不是使用intellij。它 应该工作。

+0

奏效,非常感谢建罐子 – Anas

相关问题