2017-07-28 58 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

相關問題