一,使用@Autowired注入需要使用的bean。
@Autowired
private InstitutionService institutionService;
@Autowired
private UserService service;
二,使用spring提供的获取bean的工具类来加载自动注入
WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getAutowireCapableBeanFactory().autowireBean(this);
注:该方法使用在重写的 init 方法中(只调用该servlet一次可以使用。并且使用于初始化方法。第二次调用依然没有注入)。