在Spring Boot中,可以使用内置的Tomcat服务器来监听端口请求。以下是一种常见的方式:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
@SpringBootApplication
注解:@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
@RestController
public class MyController {
@GetMapping("/hello")
public String hello() {
return "Hello, Spring Boot!";
}
}
server.port=8080
现在,你可以通过访问http://localhost:8080/hello
来测试请求,并获取到"Hello, Spring Boot!"的响应结果。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: springboot框架搭建的步骤是什么