2017-02-22 95 views
0

我有這個例外,當我嘗試啓動我的彈簧引導應用程序。我已經添加了mysql-connector-java和spring-boot-starter-jdbc依賴關係,並且不知道什麼不起作用。SpringBoot數據庫嵌入式數據庫驅動程序異常JAVA

Description: 

Cannot determine embedded database driver class for database type NONE 

Action: 

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

編輯1 這是我Maven的配置文件。

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>org.springframework</groupId> 
    <artifactId>test</artifactId> 
    <version>0.1.0</version> 

    <properties> 
     <java.version>1.8</java.version> 
    </properties> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.1.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-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.jayway.jsonpath</groupId> 
      <artifactId>json-path</artifactId> 
      <scope>test</scope> 
     </dependency> 

     <dependency> 
      <groupId>commons-dbcp</groupId> 
      <artifactId>commons-dbcp</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-jdbc</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
     </dependency> 

    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 

    <repositories> 
     <repository> 
      <id>spring-releases</id> 
      <url>https://repo.spring.io/libs-release</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>spring-releases</id> 
      <url>https://repo.spring.io/libs-release</url> 
     </pluginRepository> 
    </pluginRepositories> 
</project> 

EDIT 2 這這裏是數據源配置

public class DataSourceConfig { 

    @Bean 
    public DataSource getDataSource() { 
     BasicDataSource dataSource = new BasicDataSource(); 
     dataSource.setDriverClassName("com.mysql.jdbc.Driver"); 
     dataSource.setUrl("jdbc:mysql://localhost:3306/hcharts"); 
     dataSource.setUsername("root"); 
     dataSource.setPassword("root"); 
     return dataSource; 
    } 

    @Bean 
    public JdbcTemplate jdbcTemplate() { 
     return new JdbcTemplate(getDataSource()); 
    } 

} 
+0

鑑於你錯誤,似乎沒有嵌入式是由您的配置文件定義的,或者您的數據庫沒有指定。這可能會有用,有一些代碼示例可以幫助您瞭解這一點,特別是在彈簧引導配置中。 – DamCx

+0

如果你使用maven/gradle,你能分享一下配置文件嗎? – SaWo

+0

我編輯了我的問題。 – RockOrDead

回答

0

它看起來像你缺少你的DatasourceConfig.java文件@Configuration註解。

我試着用註釋和mvn spring-boot:run啓動罰款。如果沒有註解,我得到你曾表示,隨後由一個巨大的堆棧跟蹤文本:

應用程序未能啓動> [818分之26]


說明:

不能確定嵌入式數據庫驅動程序數據庫類型爲NONE的類

操作:

如果你想要一個嵌入式數據庫,請在classpath中放一個支持的數據庫。如果您的數據庫設置要從特定配置文件加載,您可能需要$ d才能激活它(沒有配置文件當前處於活動狀態)。

這裏是我的my/DatasourceConfig.java

package my.config; 

import org.apache.commons.dbcp.BasicDataSource; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.jdbc.core.JdbcTemplate; 

import javax.sql.DataSource; 

@Configuration 
public class DatasourceConfig { 

    @Bean 
    public DataSource getDataSource() { 
     BasicDataSource dataSource = new BasicDataSource(); 
     dataSource.setDriverClassName("com.mysql.jdbc.Driver"); 
     dataSource.setUrl("jdbc:mysql://localhost:3306/hcharts"); 
     dataSource.setUsername("root"); 
     dataSource.setPassword("root"); 
     return dataSource; 
    } 

    @Bean 
    public JdbcTemplate jdbcTemplate() { 
     return new JdbcTemplate(getDataSource()); 
    } 

} 

該應用程序也將啓動,無需@Configuration,如果你添加一個依賴於已知嵌入式數據庫一樣hsqldb

<dependencies> 
    <dependency> 
     <groupId>org.hsqldb</groupId> 
     <artifactId>hsqldb</artifactId> 
     <scope>runtime</scope> 
    </dependency> 
    ... 
</dependencies> 
相關問題