SpringCloud-Feign按照官方文档整还是报错404
看了半天书和官方文档也没找到错误的原因,请各位帮忙看看
使用的SpringCLoud版本是Dalstonsr1
使用的SpringBoot版本是1.5.9
报错内容:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is feign.FeignException: status 404 reading MyService#list(); content:
{"timestamp":1530096509277,"status":404,"error":"Not Found","message":"Not Found","path":"/web/payment/query"}
Caused by: feign.FeignException: status 404 reading MyService#list(); content:
{"timestamp":1530096509277,"status":404,"error":"Not Found","message":"Not Found","path":"/web/payment/query"}
Eurka控制台截图
Eureka应该是没什么问题,因为在同一个项目里面用Ribbon是可以正确访问到微服务的
Feign工程
Pom.xml(非完整版)
<!-- 引入自己定义的common -->
<dependency>
<groupId>com.jv</groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
<!-- actuator监控信息完善 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Ribbon需要从eureka中拿微服务 begin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- Ribbon需要从eureka中拿微服务 end-->
<!-- Ribbon begin-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
<!-- Ribbon end-->
<!-- Feign start-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<!-- Feign end-->
application.yml
server:
port: 80
eureka:
client:
register-with-eureka: false #false表示不向注册中心注册自己。
service-url:
defaultZone: http://eureka01.com:7001/eureka/,http://eureka02.com:7002/eureka/,http://eureka03.com:7003/eureka/
接口
package com.jv.cloud.service;
import com.jv.entity.Payment;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
@FeignClient("PAYMENTSERVICE")
public interface MyService {
@RequestMapping(value = "/web/payment/query",method = RequestMethod.GET)
public List<Payment> list();
@RequestMapping(value = "/web/new/query",method = RequestMethod.GET)
public List<Payment> list_new();
@RequestMapping(value = "/web/payment/discovery",method = RequestMethod.GET)
public Object discovery();
@RequestMapping(value = "/web/new/discovery",method = RequestMethod.GET)
public Object discovery_new();
}
Controller
package com.jv.cloud.controller;
import com.jv.cloud.service.MyService;
import com.jv.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class WebPaymentController {
//private PaymentService paymentService;
@Autowired
private MyService myservice;
@RequestMapping(value = "/web/payment/query",method = RequestMethod.GET)
public List<Payment> list(){ return myservice.list(); }
@RequestMapping(value = "/web/new/query",method = RequestMethod.GET)
public List<Payment> list_new(){
return myservice.list_new();
}
@RequestMapping(value = "/web/payment/discovery",method = RequestMethod.GET)
public Object discovery(){
return myservice.discovery();
}
@RequestMapping(value = "/web/new/discovery",method = RequestMethod.GET)
public Object discovery_new(){
return myservice.discovery_new();
}
}
主启动类
package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public class WebPaymentFeignApplication {
public static void main(String[] args) {
SpringApplication.run(WebPaymentFeignApplication.class, args);
}
}
如果还需要什么信息,请留言,谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
A通过Fegin访问B,在feign的service中写的请求路径A的Controller中的requestMapping中的地址。。
就是把地址是设置错了,应该指向要访问的微服务地址
回复
@特拉仔 :也就是指的 eureka注册中心的 Application名字吧
回复
在RequestMapping中指定的路径复制成了调用者的,而不是被调用者的
引用来自“特拉仔”的评论
找到答案了。。。在MyService居然指定的是自身的地址,而不是微服务的地址,扇自己一耳光
找到答案了。。。在MyService居然指定的是自身的地址,而不是微服务的地址,扇自己一耳光