SpringBoot + MyBatis 搭建后端项目 启动报错

启动项目报错

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-15 14:12:31.262 ERROR 8209 --- [           main] 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

分析

需要添加数据库的相关配置

解决方案

将启动类的注解

@SpringBootApplication
public class SsmdemoApplication {

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

}

更改为

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

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

}

添加数据源自动配置类 注解

访问成功

application.properties 更改 端口号

server.port=8082

Controller 类,写接口方法,获取接口数据
RequestMapping 的 value 是真正的路由地址,和方法名无关。

@RestController
public class FirstController {
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public String hello() {
        return "Hello Superman !";
    }
}

请求结果如下:

2849271-8b90908039044424.png
访问成功

猜你喜欢

转载自blog.csdn.net/weixin_33787529/article/details/86879158
今日推荐