@SpringBootApplication
2017-12-01 16:49
309 查看
@SpringBootApplication is a convenience annotation that adds all of the following: @Configuration tags the class as a source of bean definitions for the application context. @EnableAutoConfiguration tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings. Normally you would add @EnableWebMvc for a Spring MVC app, but Spring Boot adds it automatically when it sees spring-webmvc on the classpath. This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet. @ComponentScan tells Spring to look for other components, configurations, and services in the hello package, allowing it to find the controllers.
The MockMvc comes from Spring Test and allows you, via a set of convenient builder classes, to send HTTP requests into the DispatcherServlet and make assertions about the result. Note the use of the @AutoConfigureMockMvc together with @SpringBootTest to inject a MockMvc instance. Having used @SpringBootTest we are asking for the whole application context to be created. An alternative would be to ask Spring Boot to create only the web layers of the context using the @WebMvcTest. Spring Boot automatically tries to locate the main application class of your application in either case, but you can override it, or narrow it down, if you want to build something different.
相关文章推荐
- 【深入SpringBoot 第三章】SpringApplicationRunListener及其周期
- SpringBoot获得application.properties中数据的几种方式
- Configure a Spring Boot Web Application
- Spring Boot的@SpringBootApplication无法引入的问题
- Spring Boot学习总结(8)——SpringBoot Common application properties(application.properties)详解
- springboot war放入tomcat启动怎么指定使用外部application.properties
- spring boot application properties配置详解
- spring boot 动态切换application-xx.properties配置文件
- Spring-Boot初学之配置文件application.properties(数据源配置)
- spring boot学习总结(二)-- 关于@SpringBootApplication的一些基础知识点
- spring boot 报错:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default p
- (六)、SpringBoot 自定义配置属性,可以在application.properties中修改
- spring boot实战(第六篇)加载application资源文件源码分析
- @SpringBootApplication 注解
- springboot 修改默认加载的配置文件不为application.properties
- spring-boot application.properties配置文件和自定义配置文件
- spring boot 源码解析8-SpringApplication#run第8步
- Springboot应用静态资源不能访问,报“This application has no explicit mapping for /error”
- SpringBoot Jar包外部application文件
- spring boot-1.4.2 jar启动使用外部application.properties