1-spring stater project创建
设置springboot项目的下载地址:https://start.aliyun.com/
创建项目
创建HelloController
@RestController
publicclass HelloController {
@GetMapping("/hello")
public String hello() {
return "hello Spring Boot";
}
}
运行项目
访问项目
2-单元测试
在pom文件中添加spring-boot-starter-test测试启动器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
打开自动创建的单元测试类
编写单元测试方法
@Autowired
private HelloController helloController;
@Test
public void helloControllerTest() {
String hello = helloController.hello();
System.out.println(hello);
}
执行测试方法helloControllerTest()
进一步做测试
@SpringBootTest
class HelloControllerTests {
@Autowired
private HelloController helloController;
@Test
void testHello() {
System.out.println(helloController.sayHello());
Assert.isTrue("hello1".equals(helloController.sayHello()), "亲 ,sayHello方法返回值错误!!");
}
3-热部署
在pom文件中添加spring-boot-devtools热部署依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
设置自动构建
eclipse:
idea:IDEA配置热部署_idea热部署配置_微风粼粼的博客-CSDN博客
热部署测试
修改HelloController的方法的返回值