SpringBoot 注解 @Configuration @PropertySource @Value

@Configuration

@PropertySource

@Value

三者经常结合使用在SpringBoot项目的配置类上,@Value和@ConfigurationProperties注解不同的地方是

前者用在属性上,后者可以用在类和方法上。

@Value("${book.service.export.name}")

${}里必须是key的完整的限定名

@ConfigurationProperties通过指定prefix,可以将属性文件里的key和类的属性名的映射更简单化一点

猜你喜欢

转载自blog.csdn.net/suoyx/article/details/109343727