Spring Boot读取properties配置文件中的数据

1. 使用@Value注解(常规)

@Compontent

@Value("${demo.name}")
2. 使用Environment读取 (常规)
@Autowired

private Environment environment;

environment,getProperty("属性");
3. 使用ConfigurationProperties (推荐 适用情况: 需要注入的变量较多,并且需要与Bean关联在一起)
@Compontent

@ConfigurationProperties(prefix="demo")

@PropertySource("config.properties")

 

posted @ 2020-05-12 11:14  减字木兰花·回风落景  阅读(152)  评论(0编辑  收藏  举报