spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.52k stars 3.32k forks source link

GatewayContext are in unnamed module of loader 'app' #2875

Closed ifyun closed 1 year ago

ifyun commented 1 year ago

I use spring-cloud-gateway with some custom filters, everything is ok with spring-boot v3.0.2, now I upgrade to spring-boot v3.0.3, and get the following error when executing a request:

java.lang.ClassCastException: class io.micrometer.observation.Observation$Context cannot be cast to class org.springframework.cloud.gateway.filter.headers.observation.GatewayContext (io.micrometer.observation.Observation$Context and org.springframework.cloud.gateway.filter.headers.observation.GatewayContext are in unnamed module of loader 'app')
    at org.springframework.cloud.gateway.filter.headers.observation.ObservedResponseHttpHeadersFilter.filter(ObservedResponseHttpHeadersFilter.java:47) ~[spring-cloud-gateway-server-4.0.1.jar:4.0.1]

this is my dependencies:

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</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-gateway</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.11.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.11.5</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

Spring Cloud version: 2022.0.1

ifyun commented 1 year ago

The error is triggered on line 47 of org.springframework.cloud.gateway.filter.headers.observation.ObservedResponseHttpHeadersFilter:

GatewayContext context = (GatewayContext) childObservation.getContext(); 
ifyun commented 1 year ago

Set spring.cloud.gateway.observability.enabled to false, solved this error.

samtonyclarke commented 1 year ago

@imcloudfloating I see the see same issue with Spring Boot 3.0.4....but if we want to keep observability then we cannot disable this property. Can you reopen this issue?

vnobo commented 1 year ago

I upgraded SPRING boot 3.0.4 and it appeared!

ifyun commented 1 year ago

@vnobo If you don't need observability, just disable it, or maybe a certain observability component should be used.

ifyun commented 1 year ago

See #2877