- 安装STS插件,即Spring Tools插件:Help->Eclipse Marketplace->Find->输入sts->搜索Spring Tools->Install->安装成功后,重启Eclipse。
- 创建spring boot项目:New->Other->Spring Boot->Spring Starter Project->Next。
- Next。
- Finish。
- pom.xml添加spring-boot-starter-web,以便支持@RestController,@RequestMapping。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- 编写测试Controller。
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
*
* <p>Title: DemoController</p>
* <p>Description: </p>
* @author "zhangyq"
* @date 2019-04-17
*/
@RestController
@RequestMapping("/demo")
public class DemoController {
/**
*
* @return
*/
@RequestMapping("/hello")
public String list() {
return "Hello World";
}
}
- 测试。
- 编写测试方法。
package com.example.demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
@Test
public void contextLoads() {
System.out.println(getClass().getName());
}
}
- 测试成功,结束。