Springboot项目 手写util类 使用@Value注解读取不到yml中配置的值

@Component 
@ConfigurationProperties(prefix = "aa")
@Getter
@Setter
public class Utils {

private String username;
private String password;


private static Utils A_UTILS=new Utils ();

@Autowired
public void init(FtpUtils utils){
    Utils.A_UTILS=utils;
    }
}

注入bean

yml 文件里

aa.username=zhangshan
aa.password=123456

注入成功了

posted @ 2020-09-17 13:40  小屈工作室  阅读(2492)  评论(0编辑  收藏  举报