如何通过zuul代理从一个微服务访问另一个微服务

时间:2017-10-11 13:42:56

标签: docker spring-boot microservices netflix-eureka netflix-zuul

我正在使用spring boot开发微服务项目。这里,UI页面位于单独的微服务中的独立微服务和zuul代理中。我想通过zuul微服务访问UI页面。我在下面添加了我的项目结构。

enter image description here

UiService Application.properties:

server.port=8090
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp
spring.application.name=ui
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.instance.preferIpAddress=true
eureka.instance.leaseRenewalIntervalInSeconds=5

zuulService application.yml:

server:
port: 8080
eureka:
 instance:
  leaseRenewalIntervalInSeconds: 10
  statusPageUrlPath: /info
  healthCheckUrlPath: /health    

logging:
 level:
  ROOT: INFO
  org.springframework.web: DEBUG
zuul:
  routes:
    ui: 
      url: http://localhost:8090
ribbon:
  eager-load:
    enabled: false

我的码头撰写文件:

version: '3'
services:
  eureka:
    build: eurekaService
    ports:
      - "8761:8761"
  zuul:
    build: zuulService
    links:
     - eureka
    ports:
      - "8080:8080"
  turbine:
     build: turbineService
    links:
     - eureka
    ports:
     - "8989:8989"
  ui: 
   build: uiService
   links:
     - eureka
    ports:
     - "8090:8090"

ui服务结构:

enter image description here

我的尤里卡服务页面:

enter image description here

在docker(docker-compose up -d)中运行此项目后,当我尝试访问登录屏幕(uiService内部可用)时,会出现以下异常。怎么解决这个问题?

enter image description here

UIService主要方法:

@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
public class UIApplication {

    public static void main(String[] args) {
        SpringApplication.run(UIApplication.class, args);
     }
    }

uiService pom.xml:

 <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>com.scm</groupId>
            <artifactId>demo</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <artifactId>uiService</artifactId>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-ribbon</artifactId>
            </dependency>

           <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-hystrix</artifactId>
           </dependency>

           <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-rest</artifactId>
           </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>

             <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
             </dependency>
             <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency>

            </dependencies>
        </project>

1 个答案:

答案 0 :(得分:0)

localhost:8090/login是对UI应用的直接请求,不涉及Zuul。

如果它没有加载/显示页面,则在启动应用程序或/login不存在时可能会出错。

你介意分享日志吗?