docker - 如何通过Zuul代理从一种微服务访问另一种微服务

标签 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

我的 docker 撰写文件:
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"

uiService结构:

enter image description here

我的 Eureka 服务页面:

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>

最佳答案

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

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

您介意共享日志吗?

关于docker - 如何通过Zuul代理从一种微服务访问另一种微服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46689798/

相关文章:

linux - 在 docker 中使用 passwd 出现错误 "passwords do not match"

docker - 无法获取............哈希和不匹配

spring - Docker-compose从链接迁移到网络MongoDB数据库问题

java - Kafka Producer 注册 AppInfo mbean 时出错并且没有创建消息

node.js - HTTP2:内部服务 API 是否应该使用 http2

微服务设计中的 ElasticSearch

laravel - 如何加入docker composer php laravel

spring-boot - Dockerize MIcro-Service未在Eureka Server中注册

java - 当我们有超过 1 个 url 时如何对传入请求进行 xsd 验证

java - 我应该在哪里存储微服务的外部客户端 DTO?