spring常用注解

1.

@Controller

@Service

@Repository 

@Component

2.

@Value    主要功能获取取配置文件中值注入到指定属性上,可以使用的地方:字段上,set方法上,方法入参上,当作元注解

@Value("#{SpEl}")
@Value("${property}")
@Value("${property:default_value}")

@Autowired 

@Qualifier

@Resource

3.

@Scope

@PostConstruct 

@PreDestroy

4.

@Aspect

@Before

@AfterReturning

@Around

@AfterThrowing

@After

@Pointcut 

5.

@RequestMapping

@GetMapping

@PostMapping

@ResponseBody

@RequestBody

@RequestParam

@PathVariable

@RequestHeader

@CookieValue

@ModelAttribute

@SessionAttributes

6.

@SpringBootApplication

@RestController

@ComponentScan

@PropertySource

@ConfigurationProperties  和@Value类似都是用来注入属性,不过是批量注入,可以用在类上,可以指定前缀

或者和@Bean注解一起在方法上使用类为bean注入属性,

@Bean
@ConfigurationProperties(prefix = "my")

并且支持松散语法

my.name-first=jianwu
my.name_first=jianwu
my.name_FIrst=jianwu
类似这样的属性都可以映射到nameFirst属性上

 


 

posted @ 2018-07-07 23:49  ENU  阅读(141)  评论(0编辑  收藏  举报