要对静态变量进行注入
@Resource
private static ITecharchService techarchService;//注入为空,spring注解注入不支持静态变量注入
查资料找到可以这样注入
@Component //必须是组件,才可以用@PostConstruct
public class DDUtils{
@Resource
private ITecharchService techarchService;
private static DDUtils dd;
@PostConstruct
public void init() {
dd = this;
dd.techarchService= this.techarchService;
}
public void getA(){
//调用
dd.techarchService.getA();
}
}
时间: 2024-11-05 12:17:15