feign,404的问题我的理解:html
第一种:请求从本模块中无法出去;java
第二种:请求出去,没进入另外一个模块。web
由于本项目是springboot在父模块下的多个子模块之间使用feign的调用,且项目最终打成一个jar包发布,因此在开发中碰见的问题以下:spring
第一:请求无法出去、这里无法出去的缘由有不少,好比地址以及端口号没配置正确springboot
好比网上说的不能使用GetMapping()注解之类的,可是在这里好像是能够,有多是版本不同,更新了吧;cookie
上面这个会出现的问题有url的路径问题,啥的;反正正常经过ip以及端口发出去就行;app
第二种就是进不去:进不去;ide
我如今遇到的问题是系统登录以后;经过页面能够访问该接口,可是在系统内部相互调用的时候,会出现问题,啥子缘由呢?后来找到的结果是,给feign添加了token信息,也就是说在对另外一个模块请求的时候进行了拦截,未登陆,因此会出现了这个状况,具体添加配置以下:post
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")); } }
这里有一个额外的例子。能够看看:https://www.cnblogs.com/ft535535/p/9898147.htmlurl