将Spring Cloud Gateway与oauth2一起使用 [英] use spring cloud gateway with oauth2

查看:4676
本文介绍了将Spring Cloud Gateway与oauth2一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Spring Cloud Gateway时遇到问题

i face a problem when i using spring cloud gateway

是否有任何依赖关系直接或递归调用spring-boot-starter-tomcat

is if any dependency call spring-boot-starter-tomcat directly or recursively

它将不起作用,因为它将启动嵌入式tomcat服务器而不是Spring Cloud Gateway使用的Netty服务器

it will not work because it will start the embedded tomcat server not the netty server that spring cloud gateway use

我开始通过排除这种依赖来解决此问题

i started to solve this problem by excluding this dependency

        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>

spring cloud网关成功运行

the spring cloud gateway worked successfully

但是有时候我想使用spring-cloud-starter-oauth2来使用@ EnableOAuth2Sso

but sometimes i want to use spring-cloud-starter-oauth2 to use @EnableOAuth2Sso

我开始使用

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-oauth2</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

那个时候,我面临着抛出异常的大问题

at that time i face the big issue that throw exception saying

原因:java.lang.IllegalStateException:无法自检类org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration上的带注释的方法 ......

Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration ......

原因:java.lang.NoClassDefFoundError:javax/servlet/Filter

Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter

推荐答案

如您所见,Spring云网关使用反应模型,并且基于netty而不是tomcat.被动更改是一个重大转变,Spring Security目前不支持此更改,但正在进行中,您可以在

As you've seen, the Spring cloud gateway uses the reactive model and is based on netty rather than tomcat. The reactive change is a major shift and currently isn't supported by Spring Security but work is in progress on it and you can track it at https://github.com/spring-cloud/spring-cloud-gateway/issues/179

这篇关于将Spring Cloud Gateway与oauth2一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆