0
点赞
收藏
分享

微信扫一扫

gateway报错class path resource [org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdvi

求索大伟 2022-02-16 阅读 81

原因:

gateway引入了自定义的common包.
里边定义了统一返回值处理方法

@RestControllerAdvice(basePackages = {"com.*"}) // 这里要加上需要扫描的包
public class ResponseControllerAdvice implements ResponseBodyAdvice<Object> {
}

因为gateway不能使用web-starter所以报ResponseBodyAdvice找不到这个错误

修改结果

  • 方法1
@RestControllerAdvice(basePackages = {"com.*"}) // 这里要加上需要扫描的包
@ConditionalOnClass(ResponseBodyAdvice.class)
public class ResponseControllerAdvice implements ResponseBodyAdvice<Object> {
}
  • 方法2

gateway的启动类放到与其他代码不一样的路径下边
如:
gateway启动类路径为com.a.GatewayApplication.java
common包的路径为com.b.*.ResponseControllerAdvice .java

举报

相关推荐

0 条评论