micro-service: Zuul & consul require authentification

本秂侑毒 提交于 2019-12-11 10:33:44

问题


I'm trying to create a Spring cloud microservice application using Zuul and Consul.

I have 2 components in my project:

  1. api-gateway microservice using Zuul

  2. Hello world microservice (a simple hello world Rest Webservice)

Here is the code of The api-gateway:

 @SpringBootApplication
 @EnableZuulProxy
 @EnableDiscoveryClient
 public class ZuulApplication {

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

 }

The pom.xml

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>Brixton.M3</version>
</parent>

<properties>
    <java.version>1.8</java.version>
    <spring.cloud.consul.version>1.0.0.BUILD-SNAPSHOT</spring.cloud.consul.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

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

    <dependency>
        <!-- Setup Spring Boot -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <!-- Setup Spring MVC & REST, use Embedded Tomcat -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    <dependency>
        <!-- Spring Cloud starter -->
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter</artifactId>
    </dependency>

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

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

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-all</artifactId>
        <version>${spring.cloud.consul.version}</version>
    </dependency>

</dependencies>

application.yml

 zuul:
  routes:
    hello1:
     path: /hello1/**
     serviceId: microservice-example

logging:
  level:
   org.springframework: INFO
   com.netflix: DEBUG

bootstrap.yml

spring:
  application:
    name: edge-server

 cloud:
   consul:
    config:
      enabled: true
      host: localhost
      port: 8500

Here is the code of hello microservice:

 @SpringBootApplication
 @EnableConfigServer
 @EnableDiscoveryClient
 @RestController
 public class Application {

 @RequestMapping(value="/hello1",method = RequestMethod.GET)
 public String hello() {
    System.out.print("hello1");
    return "Hello1";
 }
 public static void main(String[] args) {
    new SpringApplicationBuilder(Application.class).web(true).run(args);
 }
}

bootstrap.yml: spring: application: name: microservice-example profiles: active: native

 cloud:
  consul:
   config:
    enabled: true
    host: localhost
    port: 8500

But, when I test my service the browser requires authentication.

来源:https://stackoverflow.com/questions/33915060/micro-service-zuul-consul-require-authentification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!