java - SpringBoot2自动配置数据源失败: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured

标签 java spring spring-boot

我的项目使用springBoot2,并且不需要连接数据库,但是springboot自动配置数据源并在启动项目时抛出异常。 我已经添加了执行,但它不起作用

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class
})
@ImportResource("classpath:spring-config-platform.xml")
public class JunoIotPlatformBoot1Application {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(JunoIotPlatformBoot1Application.class);
        Map<String,Object> map = new HashMap<>();
        map.put("server.port",8091);
        app.setDefaultProperties(map);
        app.run(args);
    }

因为我将旧的 spring 项目(xml)合并到 springboot 项目中,所以 ImportResource 是必要的。 日志是:

    2018-04-16 16:19:01,141][restartedMain][WARN][org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:557)] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

.....

    [2018-04-16 16:19:01,221][restartedMain][INFO][org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)] Stopping service [Tomcat]
    [2018-04-16 16:19:01,259][restartedMain][ERROR][org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter.report(LoggingFailureAnalysisReporter.java:42)] 

    ***************************
    APPLICATION FAILED TO START
    ***************************

    Description:

    Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.

    Reason: Failed to determine a suitable driver class


    Action:

    Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

最佳答案

您应该检查您的构建脚本,看起来您有一些不需要的启动器(以 spring-boot-starter-data-... 开头的东西)

关于java - SpringBoot2自动配置数据源失败: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49853331/

相关文章:

Spring Boot - 加载初始数据

java - Spinner setSelection() 不起作用

java - 从SpringBoot获取protobuf消息对象列表

java - 从服务器在客户端执行的 spring 双向 rmi 回调

spring - 如果未经身份验证请求uri,如何让spring安全响应未经授权(http 401代码)

spring-boot - 使用 Tomcat 为 Spring Boot 提供专用的 ExecutorService 好吗

带时间戳返回间隔的 Java Spring/PgSQL 操作

java - Tomee jpa 设置

java - 将 clojure vec 传递给 POSTGRES IN 语句(?)

java - 没有循环就循环?