看了半天书和官方文档也没找到错误的原因,请各位帮忙看看
使用的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);
}
}
如果还需要什么信息,请留言,谢谢!
<p>找到答案了。。。在MyService居然指定的是自身的地址,而不是微服务的地址,扇自己一耳光</p>
<div class='ref'><h4>引用来自“特拉仔”的评论</h4><p>找到答案了。。。在MyService居然指定的是自身的地址,而不是微服务的地址,扇自己一耳光</p>
回复 <a class="referer" target="_blank">@坐拥三千佳丽</a> : 在RequestMapping中指定的路径复制成了调用者的,而不是被调用者的
回复 <a class="referer" target="_blank">@特拉仔</a> :也就是指的 eureka注册中心的 Application名字吧
就是把地址是设置错了,应该指向要访问的微服务地址
<p>还是没看出问题在哪啊</p>
<p>A通过Fegin访问B,在feign的service中写的请求路径A的Controller中的requestMapping中的地址。。</p>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。