我们创建一个 Controller 来演示一下 Spring Boot 的神奇功能
package com.funtl.hello.spring.boot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping(value = "", method = RequestMethod.GET)
public String sayHi() {
return "Hello Spring Boot";
}
}
启动 HelloSpringBootApplication
的 main()
方法,浏览器访问 http://localhost:8080 可以看到:
Hello Spring Boot
神奇之处
- 没有配置 web.xml
- 没有配置 application.xml,Spring Boot 帮你配置了
- 没有配置 application-mvc.xml,Spring Boot 帮你配置了
- 没有配置 Tomcat,Spring Boot 内嵌了 Tomcat 容器