java Spring boot Bean 异常:无法确定数据库类型 NONE 的嵌入式数据库驱动程序类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46786592/
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
Spring boot Bean exception: Cannot determine embedded database driver class for database type NONE
提问by Klyner
I am trying to run a spring boot application which is made by someone else. I have tried to attach my local database to the application but when I run this, it gives the following error;
我正在尝试运行由其他人制作的 Spring Boot 应用程序。我试图将我的本地数据库附加到应用程序,但是当我运行它时,它给出了以下错误;
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.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).
org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration”的bean时出错:自动装配依赖项的注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配字段:私有 javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class] 中定义名称为“dataSource”的 bean 创建时出错:通过工厂方法的 Bean 实例化失败; 嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [javax.sql。DataSource]:工厂方法“dataSource”抛出异常;嵌套异常是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:无法确定数据库类型 NONE 的嵌入式数据库驱动程序类。如果您想要一个嵌入式数据库,请在类路径上放置一个受支持的数据库。如果您有要从特定配置文件加载的数据库设置,您可能需要激活它(当前没有配置文件处于活动状态)。
I am new to this and I can't find out what is the problem. Some details:
我是新手,我无法找出问题所在。一些细节:
where xxx = name of the database.
其中 xxx = 数据库的名称。
Workbench:
工作台:
Name: Local instance wampmysqld64
Host: localhost
Port: 3306
Server: MySQL Community Server (GPL)
Version: 5.7.18-log
Connector: C++ 1.1.4
Login User: root
Current User: root@localhost
SSL: Disabled
And the server is up and running.
服务器已启动并正在运行。
EDIT
编辑
pom.xml
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>****</groupId>
<artifactId>****</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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>
</project>
EDIT2
编辑2
Application.properties
应用程序属性
spring.datasource.url=jdbc:mysql://localhost:3306/xxx
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.jpa.properties.hibernate.id.new_generator_mappings = false
spring.jpa.properties.hibernate.format_sql = true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
ng.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
ng.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Application.java
应用程序.java
package gdprserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
@SpringBootApplication(exclude = RepositoryRestMvcAutoConfiguration.class)
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(final SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
}
EDIT3
编辑3
I run the Spring boot application with CMD using the command: java -jar xxx.jar
我使用以下命令通过 CMD 运行 Spring boot 应用程序: java -jar xxx.jar
采纳答案by Klyner
I found a solution to run my application with Eclipse.
我找到了一个使用 Eclipse 运行我的应用程序的解决方案。
Before I tried to run my application using Java Application -> SpringApplication with the main class: org.springframework.boot.SpringApplication
. Changing the main class to xxx.Application (where xxx is the projectname) works.
之前,我试图运行使用Java应用我的应用程序- > SpringApplication与主类:org.springframework.boot.SpringApplication
。将主类更改为 xxx.Application(其中 xxx 是项目名称)有效。
回答by fatma yakut
package com.fyakuthibernatespringboot.demo;
@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
回答by Gerry Mantha
The exception "Cannot determine embedded database driver class for database type NONE." is caused by Spring being unable to find the properties that define the database. It's telling us that it doesn't have the information necessary to create/configure the data-source.
异常“无法确定数据库类型 NONE 的嵌入式数据库驱动程序类”。是由 Spring 无法找到定义数据库的属性引起的。它告诉我们它没有创建/配置数据源所需的信息。
It's possible that it's an IDE related issue. Build your jar using maven and try run it. If you get the same exception, open the jar and look inside it to ensure it's being added correctly.
这可能是与 IDE 相关的问题。使用 maven 构建您的 jar 并尝试运行它。如果您遇到相同的异常,请打开 jar 并查看其内部以确保它被正确添加。