spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
589 stars 376 forks source link

ClassNotFoundException with AWS messaging #722

Closed mmajcenic closed 3 years ago

mmajcenic commented 3 years ago

Type: Bug

Component: SQS

Describe the bug When using spring-cloud-aws-messaging, without Webflux module and with embedded web server (as defined with WebEnvironment enum), tests fail with java.lang.ClassNotFoundException.

This happens, or at least I believe so, because WebTestClientContextCustomizer registers a WebTestClient in:

@Override
    public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
        SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(mergedConfig.getTestClass(),
                SpringBootTest.class);
        if (springBootTest.webEnvironment().isEmbedded()) {
            registerWebTestClient(context);
        }
    }

This later on causes AbstractMethodMessageHandler.detectHandlerMethods to fail because WebTestClient methods are reflectively read and some of its methods contain undefined classes (like org.springframework.web.reactive.function.server.RouterFunction).

Versions are provided in gradle config, in sample.

Sample A simple gradle config:

plugins {
    id "org.springframework.boot" version "2.4.0"
    id "io.spring.dependency-management" version "1.0.10.RELEASE"
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = "11"
targetCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.cloud:spring-cloud-starter-aws-messaging:2.2.5.RELEASE"
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType(Test) {
    useJUnitPlatform()
}

Main class:

@SpringBootApplication
public class App {

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

Test class:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class AppTest {
    // Will fail to load ApplicationContext
    @Test
    void test() {
    }
}
maciejwalkowiak commented 3 years ago

Thanks @mmajcenic for reporting.

Spring Cloud AWS (and Spring Cloud in general) are not ready yet to be used with Spring Boot 2.4.0. Hoxton release train is compatible with 2.3.x and you need to wait for Spring Cloud AWS 2.3.0 release for Spring Boot 2.4.0 compatibility.