最后解决方法如下:
@Component //申明为spring组件 public class TestUtils { @Autowired private TestService testService; //添加所需service的私有成员 private static TestUtils testUtils ; // 关键点1 静态初使化 一个工具类 这样是为了在spring初使化之前 public void setTestService(TestService testService) { this.testService = testService; } @PostConstruct //关键二 通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作 public void init() { testUtils = this; testUtils.testService = this.testService; // 初使化时将已静态化的testService实例化 } } 这样下面的代码中就可以通过 testUtils.testService 来调用service处理 转载自http://www.cnblogs.com/allforone/p/4108862.html,非常好用,我记录一下。