Spring Initializr创建工程:Springboot 启动报Failed to configure a DataSource: 'url'

mac2024-08-19  58

使用Idea的Spring Initializr

目标:使用Spring Initializr 方式创建SpringBoot工程,实现入门案例的需求。

准备工程 新建模块,选择spring initializr,然后下一步

填写项目相关信息

勾选需要的依赖启动器

完成,查看工程的目录结构如下

 

测试工程 创建HelloController

工程的src目录下创建com.itheima.controller.HelloController

@RestController public class HelloController {     /***      * 请求 /hello  输出hello springboot!      * @return      */     @RequestMapping(value = "hello2")     public String hello(){         return "hello springboot2!";     } } 启动引导类

访问: http://localhost:8080/hello2

启动报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-10-31 20:32:33.885 ERROR 17980 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be 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). Process finished with exit code 0

 原因是:

引入的jdbc 没有配置数据源:解决方法很简单: 要么暂时先把它注释起来,要么配置文件里配置好数据库信息。

 

 

 

最新回复(0)