【有奖问答】- SpringBoot 之 @Value、@Resource注解共存时的灾难!

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
    private String pattern;

    @Resource
    private RequestMappingHandlerAdapter adapter;

    //省略无关紧要代码
}
  • 如上代码,在配置类中,如果 @Value 和 @Autowired(把@Resource改成这个)是没问题的;但是不知道怎么回事如果用 @Resource的时候,@Value 取值就是 NULL。

如有高手知道原因,请在下方评论区指点一二哈~

猜你喜欢

转载自blog.csdn.net/Dream_Weave/article/details/107128846