使用带有oauth2的spring cloud gateway

ash*_*evo 10 java spring spring-oauth2 spring-cloud-gateway

我使用Spring云网关时遇到问题

如果任何依赖项直接或递归调用spring-boot-starter-tomcat

它将无法工作,因为它将启动嵌入式tomcat服务器而不是Spring云网关使用的netty服务器

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

        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
Run Code Online (Sandbox Code Playgroud)

春云网关成功运作

但有时我想使用spring-cloud-starter-oauth2来使用@ 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>
Run Code Online (Sandbox Code Playgroud)

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

引起:java.lang.IllegalStateException:无法在类org.springframework.security.oauth2.config.annotation.web.configuration.OAuth2ClientConfiguration上内省带注释的方法......

引起:java.lang.NoClassDefFoundError:javax/servlet/Filter

Rya*_*son 3

正如您所看到的,Spring 云网关使用响应式模型,并且基于 netty 而不是 tomcat。反应式更改是一个重大转变,目前 Spring Security 不支持,但相关工作正在进行中,您可以在https://github.com/spring-cloud/spring-cloud-gateway/issues/179上跟踪它。