Home:ALL Converter>Spring cloud gateway and outh2

Spring cloud gateway and outh2

Ask Time:2021-08-19T06:03:12         Author:Tom

Json Formatter

I have a legacy web application that I want to secure it by using a Spring cloud gateway with Outh2. Without Outh2, the Spring cloud gateway worked with the following application.yml

spring:
  cloud:
    gateway:
      routes:
        - id: my_route
          uri: http://MyLegacyServer:8080
          predicates:
            - Path=/**

But when I added the keycloak definition to it like the following

keycloak:
  auth-server-url: http://localhost:8083/auth
  realm: xxx
  resource: login-app
  public-client: true

I was getting the following error when at start

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.gateway.config.GatewayClassPathWarningAutoConfiguration$SpringMvcFoundOnClasspathConfiguration': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.gateway.config.GatewayClassPathWarningAutoConfiguration$SpringMvcFoundOnClasspathConfiguration]: Constructor threw exception; nested exception is org.springframework.cloud.gateway.support.MvcFoundOnClasspathException

Author:Tom,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68839821/spring-cloud-gateway-and-outh2
yy