美文网首页
SpringBoot + MyBatis 搭建后端项目 启动报错

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

作者: 南窗云 | 来源:发表于2019-01-15 14:33 被阅读0次

    启动项目报错

    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 !";
        }
    }
    

    请求结果如下:

    访问成功

    相关文章

      网友评论

          本文标题:SpringBoot + MyBatis 搭建后端项目 启动报错

          本文链接:https://www.haomeiwen.com/subject/ubaedqtx.html