Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[springboot 3.3.7 or >= 3.4.0] Required a bean of type 'org.springframework.data.rest.webmvc.mapping.Associations' that could not be found. #2828

Open
gquintillan opened this issue Dec 19, 2024 · 4 comments

Comments

@gquintillan
Copy link

Describe the bug
When I upgrade from SpringBoot 3.3.6 to 3.3.7 (with springdoc-openapi 2.6.0) or 3.4.1 (with springdoc-openapi 2.7.0) I get the following error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 2 of method springRepositoryRestResourceProvider in org.springdoc.core.configuration.SpringDocDataRestConfiguration$SpringRepositoryRestResourceProviderConfiguration required a bean of type 'org.springframework.data.rest.webmvc.mapping.Associations' that could not be found.

This is the stacktrace when I set debug: true in the application.yml:

2024-12-19T16:50:31.739+01:00 DEBUG 14485 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : Application failed to start due to an exception

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.data.rest.webmvc.mapping.Associations' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:2144) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1594) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1519) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:913) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:546) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1357) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:289) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory$2.resolveCandidate(DefaultListableBeanFactory.java:2191) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1631) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.createOptionalDependency(DefaultListableBeanFactory.java:2198) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1503) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:913) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:546) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1357) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:289) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1122) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1093) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1030) ~[spring-beans-6.2.1.jar:6.2.1]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987) ~[spring-context-6.2.1.jar:6.2.1]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.2.1.jar:6.2.1]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.4.1.jar:3.4.1]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.4.1.jar:3.4.1]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.4.1.jar:3.4.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.4.1.jar:3.4.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.4.1.jar:3.4.1]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.4.1.jar:3.4.1]

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?: 3.3.7 or >= 3.4.0
  • What modules and versions of springdoc-openapi are you using?: springdoc-openapi-starter-webmvc-ui 2.6.0 2.7.0
  • Provide with a sample code (HelloController) or Test that reproduces the problem:

In the Main class (@SpringBootApplication) I'm using the following Beans:

  • import io.swagger.v3.oas.models.Components;
  • import io.swagger.v3.oas.models.OpenAPI;
  • import io.swagger.v3.oas.models.info.Info;
  • import org.springdoc.core.models.GroupedOpenApi;

In the Rest Controller (@RestController) I'm using the following annotations:

  • import io.swagger.v3.oas.annotations.Operation;
  • import io.swagger.v3.oas.annotations.tags.Tag;

Expected behavior
The application starts without errors.

Additional context
The application is a SpringBoot Application with Spring Data Rest and Spring Data Elastic Search

          <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
@jkjome
Copy link

jkjome commented Dec 20, 2024

I encounter the same behavior with Spring Boot 3.4.1, though it works fine with 3.4.0. That said, I can resolve under 3.4.1 if I override spring-data-rest-webmvc with version 4.4.0. It's version 4.4.1 that appears incompatible with Springdoc 2.7.0.

I should mention one oddity. Of two of my apps that use Springdoc 2.7.0, one works fine with Spring Boot 3.4.1 and the other doesn't. It's not clear to me what the difference is?

@MarkusRohlof
Copy link

Same issue here. Overriding spring-data-rest-webmvc with 4.4.0 worked for me as well.

@jkjome
Copy link

jkjome commented Dec 23, 2024

I believe the problem is related to spring-boot-devtools. If said dependency is removed from the POM, the app runs fine in the IDE. Also, JUnit test running is unaffected either way. The same is true for running as a plain old Jar app... outside the context of an IDE. And the only difference, of any consequence, between v4.4.0 and v4.4.1 of spring-data-rest-webmvc is the introduction of file META-INF/spring-devtools.properties, with contents...

restart.include.spring-data-rest-webmvc:/spring-data-rest-webmvc-[\\w-\\.]+\.jar

That said, I don't know why the above results in the unfortunate Dev Tools behavior.

@gquintillan
Copy link
Author

gquintillan commented Dec 23, 2024

Thank you for the feedback, I can confirm that it only happens when running the application with spring-boot-devtools, when I run the JAR the problem does not occur. Moreover, if I remove the dependency spring-boot-devtools I have no issues when running the application with ./mvnw spring-boot:run or the IDE.

The commit from spring-data-rest says:

We now declare explicit Spring Boot DevTools configuration to include Spring Data REST WebMVC and HAL Explorer in the restart classloader to prevent proxying issues with package protected types.

spring-projects/spring-data-rest@f718afa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants