Spring Boot 常用注解

1:@SpringBootApplication

SpringBootApplication:
包含了@ComponentScan、@Configuration和@EnableAutoConfiguration注解。
其中@ComponentScan让spring Boot扫描到Configuration类并把它加入到程序上下文。

@SpringBootApplication:申明让spring boot自动给程序进行必要的配置,这个配置等同于:@Configuration ,@EnableAutoConfiguration 和 @ComponentScan 三个配置。

package com.example.myproject; 
import  org.springframework.boot.SpringApplication; 
import  org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication  
//与@Configuration @EnableAutoConfiguration @ComponentScan相同
public  class  Application  { 
    public  static  void  main (String [] args)  { 
        SpringApplication.run(Application.class,args); 
    } 
}

2:@Configuration

@Configuration 等价于spring的XML配置文件即:(等价于 < beans > < /beans >)

3:@EnableAutoConfiguration

Spring Boot自动配置(自动配置):尝试根据您添加的jar依赖自动配置您的Spring应用。

4:@ComponentScan

@ComponentScan等价于<context:component-scan base-package=”com.xxx.xxx”/> ,表示将类自动发现扫描组件

5:@Component

@Component:泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注。

6:@RestController

@RestController:用于标注控制层组件(如struts中的action),@ ResponseBody和@Controller的合集。@responseBody注解的作用是将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML

7:@Autowired

@Autowired默认按类型装配(这个注解是属业spring的),默认情况下必须要求依赖对象必须存在,如果要允许null值,可以设置它的required属性为false,如:@Autowired(required=false) ,如果我们想使用名称装配可以结合@Qualifier注解进行使用 如下:

@Autowired()
@Qualifier("xxxDao")
private XxxDao xxxDao;

8:@PathVariable

@PathVariable(“参数名称”)获取URL中对应的参数值。如果@PathVariable标明参数名称,则参数名称必须和URL中参数名称一致。

Alt
在这里插入图片描述

提示
本人以抱着学习的态度去分享,以上内容如有雷同,不胜荣幸!如有不足,欢迎评论留言!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值