1. 使用@Value注解(常规)
@Compontent
@Value("${demo.name}")
@Autowired
private Environment environment;
environment,getProperty("属性");
3. 使用ConfigurationProperties (推荐 适用情况: 需要注入的变量较多,并且需要与Bean关联在一起)
@Compontent
@ConfigurationProperties(prefix="demo")
@PropertySource("config.properties")