Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured解决办法

洼地云 tuoyidashi.png

新建springboot项目启动出错:Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

出现错误的原因是我在官网[https://start.spring.io/]生成框架代码的时候,加入的Mybatis依赖。因此,autoconfig会去读取数据源配置,而新建的项目还没有配置数据源,所以会导致异常出现。

解决办法:

1.去掉maven数据库依赖;
2.在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)  
public class BdservoApplication {  

    public static void main(String[] args) {  
        SpringApplication.run(BdservoApplication.class, args);  
    }  
}
赞(0)
未经允许禁止转载:优米格 » Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured解决办法

评论 抢沙发

合作&反馈&投稿

商务合作、问题反馈、投稿,欢迎联系

广告合作侵权联系

登录

找回密码

注册