PersonalDiary

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

@Compontent

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

private Environment environment;

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

@ConfigurationProperties(prefix="demo")

@PropertySource("config.properties")

 

分类:

技术点:

相关文章: