java - Spring boot Bean异常: Cannot determine embedded database driver class for database type NONE

标签 java mysql spring spring-boot mysql-workbench

我正在尝试运行由其他人制作的 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).

我是新手,我无法找出问题所在。一些细节:

其中 xxx = 数据库名称。

工作台:

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

服务器已启动并正在运行。

编辑

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>

编辑2

应用程序属性

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

Application.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();
    }
}

编辑3

我使用以下命令通过 CMD 运行 Spring boot 应用程序:java -jar xxx.jar

最佳答案

package com.fyakuthibernatespringboot.demo;


@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

关于java - Spring boot Bean异常: Cannot determine embedded database driver class for database type NONE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46786592/

相关文章:

mysql 特定查询

mysql - SQL 模式级别约束

java - 用户登录和 session 劫持后的 Spring Security cookie

java - 使用 JMX 导出 Spring @Bean 对象

java - 如何使用spring消息PropertyPlaceholderConfigurer传递参数?

java - 使用 Java 中的 Selenium Webdriver 以不同用户身份运行 IE

java - 为什么两个 RDD 的交集在 Spark 中不起作用

mysql - 来自 mysql 的 JavaFx 组合框

java - 具有相同类名(不同包)的两个 Spring 服务 Bean 即使使用限定符也会抛出错误

java - 关闭阅读器,使输入流保持打开状态