美文网首页
spring cloud_zuul

spring cloud_zuul

作者: Shokka | 来源:发表于2018-04-27 14:47 被阅读0次

    注册路由时报错:

    路由Forwarding error错误

    原因:

    配置文件通过微服务id找不到微服务:

    zuul:
    
      routes:
        #路由转发
        api-basicS:
          path: /api-basicS/**
          serverId: basic_servic
    

    修改为:

    zuul:
    
      routes:
        #路由转发
        api-basicS:
          path: /api-basicS/**
          url: http://localhost:8763
    

    虽然不报错能正常使用
    但是扔没解决如何通过serverId找到服务,希望大神指点。

    这里列出zuul的gradle配置:(可能有部分是多余的

    dependencies {
        compile('org.springframework.cloud:spring-cloud-config-server')
        compile('org.springframework.cloud:spring-cloud-starter-eureka')
        compile('org.springframework.boot:spring-boot-starter-web')
        compile('org.springframework.cloud:spring-cloud-starter-netflix-ribbon')
        compile('org.springframework.cloud:spring-cloud-starter-netflix-zuul')
        compile('org.springframework.cloud:spring-cloud-starter-hystrix')
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }
    

    以下是basic_servic服务的配置:

    eureka:
      client:
        serviceUrl:
          defaultZone: http://localhost:8761/eureka/
    server:
      port: 8763
    spring:
      application:
        name: basic_servic
    

    Application.java:

    package com.discern.car;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
    @EnableDiscoveryClient
    @EnableEurekaClient
    @RestController
    public class CarApplication {
    
    
        @Value("${server.port}")
        String port;
        @RequestMapping("/hi")
        public String home(@RequestParam String name) {
            return "hi "+name+",i am from port:" +port;
        }
        public static void main(String[] args) {
            SpringApplication.run(CarApplication.class, args);
        }
    }
    
    
    
    

    相关文章

      网友评论

          本文标题:spring cloud_zuul

          本文链接:https://www.haomeiwen.com/subject/avwblftx.html