SpringBoot环境搭建以及热部署?

1.创建Maven工程。

 

2.添加SpringBoot起步依赖。

SpringBoot要求,项目要继承SpringBoot的起步依赖spring-boot-starter-parent,所以我们在pom.xml中添加下面的代码:
<parent> 
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>

 SpringBoot要集成SpringMVC进行Controller的开发,所以要添加web功能的起步依赖,不需要又导入spring,又导入SpringMVC,直接导入web功能即可:

<dependencies> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-starter-web</artifactId> 
</dependency> 
</dependencies>

 

3.编写SpringBoot引导类。

要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问:
package com.itIcey;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MySpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(MySpringBootApplication.class);
    }
}

 

4.编写Controller。

在引导类MySpringBootApplication同级包或者子级包中创建QuickStartController:
package com.itIcey.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class QuickStartController {
    @RequestMapping("/quick")
    @ResponseBody
    public String quick(){
        return "hello springboot";
    }
}

 

5.测试:执行起步类的主方法,报错如下:

 

 根据报错原因,好像是跟空间不足有关,于是把电脑里用不到的东西清理了一下,果然可以了:

 

 

 

通过日志发现,Tomcat started on port(s): 8080 (http) with context path '',tomcat已经起步,端口监听8080,web应用的虚拟工程名称为空。
打开浏览器访问url地址为:http://localhost:8080/quick,成功啦!

 6.SpringBoot工程热部署:

在pom.xml中插入如下代码:

<!--热部署配置--> 
<dependency> 
<groupId>org.springframework.boot</groupId> 
<artifactId>spring-boot-devtools</artifactId> 
</dependency>

发现并没有起作用?

出现这种情况,并不是热部署配置问题,其根本原因是因为Intellij IEDA默认情况下不会自动编译,需要对IDEA进
行自动编译的设置,如下:File-Settings-Compiler-Build project automatically
 
然后 Shift+Ctrl+Alt+/,选择Registry

 

 竟然还不行?

IDEA菜单栏--RUN--Edit Configurations--SpringBoot--目标项目--热更新

 

 ok,终于可以啦!

 
 
 
posted @ 2020-03-22 18:24  遍唱阳春  阅读(300)  评论(0编辑  收藏  举报