springboot无法注入httpservlectRequest

背景:

SpringBoot开发接口,controller方法中注入javax.servlet.http.HttpServletRequest

访问接口时报错,Failed to resolve argument 0 of type 'javax.servlet.http.HttpServletRequest' on public java.lang.Object 

原因:httpservlectRequest是web容器的,不是交给Spring容器管理的。

解决:pom中引入spring-boot-starter-web。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

搞了一个公众号PostgreSQL运维技术,欢迎来踩~

悄悄放一张:


版权声明:本文为qq_35462323原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。