SpringMVC Web项目升级为Springboot项目(一)

一、项目改为Springboot项目

1.将pom中所有spring相关依赖删除,添加spring-boot-starter及spring-boot-starter-web(项目中可能有其他spring依赖,单独添加即可)

2.将pom中mybatis相关依赖删除,添加mybatis-spring-boot-starter

3.添加application.properties文件,在其中配置数据库相关配置项

spring.datasource.url=jdbc:mysql://202.16.199.1:3306/Book?useSSL=true&verifyServerCertificate=false&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=123123
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5

 

4.添加Application类

package com.gauge.childheart;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
@ComponentScan(basePackages = "com.gauge.childheart.*")
@MapperScan(value = "com.gauge.childheart.mapper")
public class Application extends SpringBootServletInitializer {

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

    @RequestMapping("/")
    public String hello() {
        return "hello";
    }
}

 

5.报错:Consider defining a bean of type xxxxMapper in your configuration

在Application类添加注解@MapperScan(value = "com.xxxx.mapper")

 

至此,项目可以正常启动

 

转载于:https://www.cnblogs.com/punkrocker/p/10654380.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值