SpringBoot启动类注解,是干什么用的
时间: 2024-05-24 17:11:23 浏览: 22
SpringBoot启动类注解是用来标识一个类是SpringBoot应用程序的入口类。它可以被用来代替传统的XML配置文件,简化SpringBoot应用程序的配置工作。在启动类中,可以定义一些基础配置,例如设置应用程序的端口号、扫描包的路径、配置数据源等。同时,启动类还可以使用其他注解来进一步配置应用程序,例如开启自动配置、启用Web MVC等。通过使用SpringBoot启动类注解,可以让SpringBoot应用程序更加简洁、易于维护和部署。常见的SpringBoot启动类注解有@SpringBootApplication、@EnableAutoConfiguration和@SpringBootConfiguration等。
相关问题
springboot启动类注解
Spring Boot的启动类注解是@SpringBootApplication。这个注解是一个组合注解,它包含了三个主要的注解:@SpringBootConfiguration、@EnableAutoConfiguration和@ComponentScan。其中,@SpringBootConfiguration是一个配置类注解,用于标识这个类是一个配置文件类。@EnableAutoConfiguration是用来启用自动配置的注解,它会根据类路径下的依赖自动配置Spring应用程序。@ComponentScan是用来扫描和注册Spring的组件的注解。总体来说,@SpringBootApplication注解简化了Spring Boot应用程序的配置和启动过程。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [springboot启动注解](https://blog.csdn.net/web17508858916/article/details/126511421)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [可能是全网最全的SpringBoot启动流程源码分析(基于 2.1.5 版本)](https://download.csdn.net/download/weixin_38590738/14852963)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
springboot启动类常用注解
SpringBoot启动类常用的注解包括:
1. @SpringBootApplication:这是SpringBoot的重要注解,作用在入口启动类上,是一个组合注解,包含了@Configuration、@EnableAutoConfiguration和@ComponentScan。通常用在主类上。
2. @Controller:用于标注控制层组件,需要返回页面时请使用@Controller而不是@RestController。它定义了一个控制器类,在Spring项目中负责将用户发来的URL请求转发到对应的服务接口(service层)。通常与@RequestMapping注解配合使用。
3. @ComponentScan:用于组件扫描,可以自动发现和装配一些Bean。它会扫描带有@Component、@Controller、@Service等注解的类,并将其注册为Bean。可以自动收集所有的Spring组件,包括@Configuration类。
以上是SpringBoot启动类常用的注解。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* *2* *3* [SpringBoot的常用注解](https://blog.csdn.net/i168wintop/article/details/94122323)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)