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,成功啦!


502 Bad Gateway


nginx

猜你喜欢

转载自www.cnblogs.com/iceywu/p/12547486.html