springboot中@Autowired注入为null
问题描述
在项目中,对一些工具类使用了@Component标注,然后在service层去注入该工具类,断点显示注入的工具类为null。
解决方案
@Component
@Slf4j
public class MailUtils {
public static MailUtils mailUtils;
@PostConstruct
public void init(){
mailUtils = this;
}
}
调用时使用MailUtils.mailUtils.methodName()进行调用

浙公网安备 33010602011771号