通过setter注入
主要针对从properties引入变量
- 声明
//声明变量
private static String spring_profiles_active;
- 注入
//setter方法不可以为static
@Value("${spring.profiles.active}")
public void setSpring_profiles_active(String spring_profiles_active) {
this.spring_profiles_active = spring_profiles_active;
}
- spring扫描
最后在所属类上加上@Component注解,以便让spring扫描到
@Component