feign.FeignException$NotFound: [404] during [GET] to [http://127.0.0.1:8011/csm/api/v1.0/system/platform/test] [SysPlatformIf#querySysManagerIp()]: [{"timestamp":1583803232721,"status":

feign,404的问题个人理解:

第一种:请求从本模块中没法出去;

第二种:请求出去,没进入另一个模块。

因为本项目是springboot在父模块下的多个子模块之间使用feign的调用,且项目最终打成一个jar包发布,所以在开发中遇见的问题如下:

第一:请求没法出去、这里没法出去的原因有很多,比如地址以及端口号没配置正确

 比如网上说的不能使用GetMapping()注解之类的,但是在这里好像是可以,有可能是版本不一样,更新了吧;

 上面这个会出现的问题有url的路径问题,啥的;反正正常通过ip以及端口发出去就行;

第二种就是进不去:进不去;

我现在遇到的问题是系统登陆之后;通过页面可以访问该接口,但是在系统内部相互调用的时候,会出现问题,啥子原因呢?后来找到的结果是,给feign添加了token信息,也就是说在对另一个模块请求的时候进行了拦截,未登录,所以会出现了这个情况,具体添加配置如下:

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 跨模块获取登录信息
 * author 
 * date 2020/2/20 0020 16:11
 */
@Configuration
public class FeignConfig implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

        HttpServletRequest request = requestAttributes.getRequest();
        requestTemplate.header("postman-token",request.getHeader("postman-token"));
        requestTemplate.header("cookie",request.getHeader("cookie"));
    }
}

猜你喜欢

转载自www.cnblogs.com/notchangeworld/p/12460579.html