SpringCloudGateway中出现No primary or default constructor和web-application-type=reactive or remove

简介: SpringCloudGateway中出现No primary or default constructor和web-application-type=reactive or remove

报错1:Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.

 

报错2:No primary or default constructor found for interface javax.servlet.http.HttpServletRequest。java.lang.NoSuchMethodException: javax.servlet.http.HttpServletResponse

 

一开始我是先报错1,然后就通过,在yml 配置文件中配置以下代码即可。或者在pom文件里注释掉spring-boot-starter-web的依赖

main:
    web-application-type: reactive

后面出现了报错2,在使用HttpServletResponse或HttpServletRequest方法的时候说没该方法。这时候我就想到了会不会是版本问题,但总的来想是不大可能的。毕竟别人导入的依赖是一样也可以。后面想到gateway组件中的spring-boot-starter-webflux也是有web功能但没有这个方法,而我傻逼的是把这个gateway组件放在了父类项目的pom中......(实际应该放在gateway项目中让gateway项目用他自己那套webflux),因为之前我已经在yml中把spring-boot-starter-web注释掉了这样就导致了只用了gateway网关的web发生没有这个方法的报错。

总的来说是:

在controller的接口类的方法参数中使用HttpServletResponse或HttpServletRequest作为参数的时候要用到spring-boot-starter-web依赖,但是一旦修改为了spring-boot-starter-webflux依赖,那么就不能再方法参数中使用HttpServletResponse或HttpServletRequest了。

且gateway组件放在父类项目且父类项目有中spring-boot-starter-web组件的话则会发生冲突

目录
相关文章
|
Java 数据库连接 mybatis
Consider defining a bean of type ‘com.example.democrud.democurd.usermapper.DaoMapper‘ in your config
Consider defining a bean of type ‘com.example.democrud.democurd.usermapper.DaoMapper‘ in your config
214 0
|
7月前
|
JavaScript
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
Vue报错 Invalid default value for prop “list“: Props with type Object/Array must use a factory
362 0
|
7月前
|
前端开发 开发者
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
95 1
|
7月前
|
JavaScript
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
|
Java Spring
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
required a bean of type ‘org.springframework.web.client.RestTemplate‘ that could not be found.
|
JavaScript 前端开发
成功解决Component template should contain exactly one root element
成功解决Component template should contain exactly one root element
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
JSON 前端开发 Java
【elementUI + Spring报错解决方案】Required request part ‘*****‘ is not present
【elementUI + Spring报错解决方案】Required request part ‘*****‘ is not present
1056 0
【elementUI + Spring报错解决方案】Required request part ‘*****‘ is not present
|
Java 开发工具
gradle Could not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.crea
gradle Could not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.createCrossBuildFileHashCache().
6792 0
|
应用服务中间件
Cannot change version of project facet Dynamic Web Module to 3.0
Cannot change version of project facet Dynamic Web Module to 3.0