1.首先非controller类使用@Component实例化到spring容器中
2.定义@PostConstruct的初始化方法
举例
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Test {
@Autowired
public XxService xService;
public static Test test;
@PostConstruct
public void init(){
test= this;
//test.xService = this.xService;
}
//方法使用
test.xService.getxxxx();
}