标签:spec delegate tap 支持 get starting 功能 add als
This
class-levelannotation tells Spring Boot to “guess” how you want to configure Spring, based on the jar dependencies that you have added. Sincespring-boot-starter-webaddedTomcatandSpring MVC, the auto-configuration assumes that you are developing aweb applicationandsets up Springaccordingly.
pom.xml文件中的依赖(如spring-boot-starter-web),来构建相关环境(Tomcat—web容器和Spring MVC)This is known as a stereotype annotation. It provides hints for people reading the code and for Spring that the
class plays a specific role. In this case, our class is a web@Controller, so Spring considers it when handling incoming web requests.
json,响应给浏览器
@Controller(实例化当前类为一个控制器)与@ResponseBody(将当前方法返回值转换为json,响应给浏览器)的组合,支持RESTful访问方 式,返回结果都是json字符串。区别见[Controller与RestController区别](# Controller与RestController区别)The
@RequestMappingannotation provides “routing” information. It tells Spring that any HTTP request with the/chenzfpath should be mapped to thehellomethod. The@RestControllerannotation tells Spring to render the resulting string directly back to the caller.
类(加入命名空间)与方法(指定具体路径)@GetMapping限定请求方式只能是Get,并指定路径,可以被RequestMapping替代,一般只用于修饰方法@PostMapping、@PutMapping、@DeleteMapping类似,也用于限定请求方式@SpringBootApplication 注解等价于
@SpringBootConfiguration:标识注解,标识这是一个Spring Boot的配置类@EnableAutoConfiguration :自动与项目中集成的第三方技术进行集成@ComponentScan:扫描入口类所在子包以及子包后代包中注解SpringApplication.run(Application.class, args);
This is a standard method that follows the Java convention for an application entry point. Our main method delegates to Spring Boot’s
SpringApplicationclass by callingrun.SpringApplicationbootstraps our application, starting Spring, which, in turn, starts the auto-configured Tomcat web server. We need to passApplication.classas an argument to therunmethod to tellSpringApplicationwhich is the primary Spring component. Theargsarray is also passed through to expose any command-line arguments.
SpringApplication,并告知当前Spring Boot主应用类是谁,从而启动Spring Boot中Tomcat容器args可以在启动时指定外部参数,来覆盖Spring Boot中一些默认配置
标签:spec delegate tap 支持 get starting 功能 add als
原文地址:https://www.cnblogs.com/chenzufeng/p/14850001.html