Could not autowire field: private javax.servlet.http.HttpServletRequest

在写单元测试类的时候,报错,废了很大劲才给调试好,给大家分享下。

Could not autowire field: private javax.servlet.http.HttpServletRequest

 

完整错误如下:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'buskjjlzjwyhpsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.servlet.http.HttpServletRequest com.yunhwa.business.controller.buskjjlzjwyhpsController.request; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.servlet.http.HttpServletRequest] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

 最后加入该注解完美解决

Could not autowire field: private javax.servlet.http.HttpServletRequest