zoukankan      html  css  js  c++  java
  • Spring boot 数据源未配置异常

    问题

    在使Springboot自动生成的项目框架时如果选择了数据源,比如选择了mysql,生成项目之后,启动会报一下异常:

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

    问题分析

    导致此问题的原因为,springboot生成的项目启动时会自动注入数据源。而此时在配置文件中并没有配置数据源信息,因此会抛出异常。

    解决方案

    (1)如果暂时不需要数据源,可将pom文件中的mysql和mybatis(或其他数据源框架)注释掉,即可正常启动。 
    (2)在@SpringBootApplication中排除其注入

    @SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
    • 1

    (3)提供数据源的配置或其他数据源配置,此处提供默认配置示例,在application.properties文件中添加以下配置项:

    # 主数据源,默认的
    #spring.datasource.type=com.zaxxer.hikari.HikariDataSource
    
    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/test
    spring.datasource.username=root
    spring.datasource.password=root

    引入依赖:
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
     
  • 相关阅读:
    easyui combobox 获取焦点
    easyui combobox keyhandler使用
    easyui combobox 取值
    Tomcat启动超时问题Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds
    spring定时器中如何获取servletcontext
    不用asp.net MVC,用WebForm照样能够实现MVC
    打印从1到最大的n位数
    [NOIP复习]第三章:动态规划
    Java并发与同步
    Bootstrap的js插件之按钮(button)
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/8399287.html
Copyright © 2011-2022 走看看