@Component //加注解
public class xxx自己创建的类{
private static xxx自己创建的类 oneself;
@Resource
private xxx注入其他要使用的类 other;
/**
* 通过@PostConstruct实现初始化bean之前进行的操作
*/
@PostConstruct
private void init() {
// 初使化时将已静态化的Service实例化
oneself= this;
}
public void test(){
// 使用
oneself.other.other里面的方法();
}
}
Java springBoot 自定义类中使用@Resource、@Autowired 注入报null异常解决方案 (java.lang.NullPointerException)
最新推荐文章于 2023-10-25 09:36:44 发布