0

使用Spring云合同来验证我的生产者和消费者之间的合同。在我的客户控制器中,我使用Feign客户端调用另一种微服务方法来获取一些数据。但是现在春天的云合同使得这种微服务的存根是不可能的。春季云合同 - Feign客户

在Netflix OSS中使用Spring Cloud。

配置服务和尤里卡已启动。现在我在本地安装我的制作人在端口8090.使用Feign客户端的消费者呼叫生产者获取一些数据。现在我得到500错误。它显示没有找到URL。最接近的匹配是/ ping。我相信Feign客户端无法模拟,它不知何故试图与本地安装的制作人联系,而不是联系尤里卡。你能帮我吗?

任何示例或任何想法都会很棒。

感谢

回答

1

这是可能的,这是我的JUnit测试,做它(ParticipantsService使用假死客户端)

@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 
@AutoConfigureStubRunner(ids = {"com.ryanjbaxter.spring.cloud:ocr-participants:+:stubs"}, workOffline = true) 
@DirtiesContext 
@ActiveProfiles("test") 
public class OcrRacesApplicationTestsBase { 

    @Autowired 
    protected ParticipantsService participantsService; 

    private List<Participant> participants = new ArrayList<>(); 


    //Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156 
    static { 
     System.setProperty("eureka.client.enabled", "false"); 
     System.setProperty("spring.cloud.config.failFast", "false"); 
    } 

    @Before 
    public void setup() { 
     this.participants = new ArrayList<>(); 
     this.participants.add(new Participant("Ryan", "Baxter", "MA", "S", Arrays.asList("123", "456"))); 
     this.participants.add(new Participant("Stephanie", "Baxter", "MA", "S", Arrays.asList("456"))); 
    } 

    @After 
    public void tearDown() { 
     this.participants = new ArrayList<>(); 
    } 

    @Test 
    public void contextLoads() { 
     List<Participant> participantList = participantsService.getAllParticipants(); 
     assertEquals(participants, participantList); 
    } 
} 
+0

据我以前不工作。我也尝试过。我更新了这个问题。你可以看一下 – blackOcean

+0

你不需要使用Eureka或配置服务器来使合同工作。基于它无法找到与之相匹配的合同这一事实,似乎请求发送与您的合同之间可能存在差异。你可能会发布合同和请求被发送? –

+0

更新:我认为,从Dalston开始,这已经修复了! –