你应该有在 web.xml 配置了监听 , 才能在普通类中直接注入这个
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
spring Mvc 要接收参数有: 1 HttpServletRequest 2 HttpServletResponse 3 HttpSession 4 Model 5 请求参数
可以不用注入的
@
Controllerpublic class MyController{
// @
Autowired // private HttpSession session;
@
RequestMapping("/hello")
//你漏了方法名称
public String helloWorld(HttpSession session){
return "hello world";
}
}