在您的问题中
<bean name="ProductServlet" class="com.epam.productshop.controller.ProductServlet" scope="singleton">
<property name="requestHelper" ref="requestHelper"/>
</bean>
您不能使用spring容器实例化servlet,它们是由servlet容器实例化的。您只是在声明ProductServlet的另一个实例。
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, getServletContext());`
要注入requestHelper @Autowired
,请在Servlet中声明带注释的字段或属性:
private RequestHelper requestHelper;
@Autowired
public void setRequestHelper(RequestHelper requestHelper){
this.requestHelper = requestHelper;
}
来自 processInjectionBasedOnServletContext javadoc:
处理 注射给定目标对象,根据与存储在ServletContext当前根web应用上下文。