springboot怎样监听端口要求
在Spring Boot中,可使用内置的Tomcat服务器来监听端口要求。以下是一种常见的方式:
org.springframework.boot
spring-boot-starter-web
@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!"的响应结果。
TOP