@bnasslahsen Use the following build.gradle: Show
and application.properties: spring.cloud.compatibility-verifier.enabled=true spring.cloud.compatibility-verifier.compatible-boot-versions=2.6SampleController.java: @RestController public class SampleController { @Operation(summary = "test") @GetMapping("/test") public String test() { return "test"; } }I tested it and it reproduces the problem. Using springdoc-openapi-ui in this setup changes the Spring Boot version to 2.7.0 under the hood, and it is captured by the compatibility verifier. At the same time, many dependencies still remain at 2.6.10 version, which may cause hard-to-capture-issues. The problem does not appear, when one uses Spring Boot Gradle Plugin which appears to enforce single version. Some context:
The root cause is that the library uses spring-boot-starter-parent:2.7.0 in the POM file: https://github.com/springdoc/springdoc-openapi/blob/v1.6.9/pom.xml whereas it should use 2.6.10. I'd expect that if the project claims minor version compatiblity 1.6 <-> 2.6, it should depend exactly on this framework version. Reason: Spark has earlier version of 'javax.validation:validation-api', without "getClockProviderClassName" method. Options like "userClassPathFirst" can help: Classpath resolution between spark uber jar and spark-submit --jars when similar classes exist in both The spring boot exception org.springframework.beans.factory.BeanCreationException: Error creating bean with name happens when a problem occurs when the BeanFactory creates a bean. If the BeanFactory encounters an error when creating a bean from either bean definition or auto-configuration, the BeanCreationException will be thrown. The exception Error creating bean with name defined in file happens most of the time in the @Autowired annotation. If BeanCreationException is found in the spring boot application, the nested exception would reveal the root cause of the exception. There are multiple nested exceptions that trigger BeanCreationException: Error creating bean with name in the spring boot application. The nested exception will help you to fix BeanCreationException. The following list describes the common root causes that are seen in the nested exception. NoSuchBeanDefinitionException: No qualifying bean of typeThis exception occurs when the bean is not available or defined while auto-wired in another class. s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘zoo’: Unsatisfied dependency expressed through field ‘lion’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.yawintutor.Lion’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} If the root cause exception is displayed as No qualifying bean of type then follow the link below to resolve this exception. NoSuchBeanDefinitionException: No qualifying bean of typeNoSuchBeanDefinitionException: No bean named availableThis exception happens when you try to access a bean that is not available or is not defined in the spring boot context. Exception in thread “main” org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘lion1’ available If the root cause exception is displayed as No qualifying bean of type then follow the link below to resolve this exception. NoSuchBeanDefinitionException: No bean named availableBeanCurrentlyInCreationException: Error creating bean with name: Requested bean is currently in creationThis exception happens when two beans are in circular dependences with each other. s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘department’ defined in file [/SpringBootBean/target/classes/com/yawintutor/Department.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘lion’ defined in file [/SpringBootBean/target/classes/com/yawintutor/Lion.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘tiger’ defined in file [/SpringBootBean/target/classes/com/yawintutor/Tiger.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name ‘lion’: Requested bean is currently in creation: Is there an unresolvable circular reference? If the root cause exception is displayed as Requested bean is currently in creation then follow the link below to resolve this exception. BeanCurrentlyInCreationException: Error creating bean with name: Requested bean is currently in creationNoUniqueBeanDefinitionException: No qualifying bean of type available: expected single matching bean but foundThis exception occurs when the bean is auto-wired that matches two or more loaded beans in the spring boot application context. s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘zoo’: Unsatisfied dependency expressed through field ‘animal’; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ‘com.yawintutor.Animal’ available: expected single matching bean but found 2: lion,tiger If the root cause exception is displayed as expected single matching bean but found then follow the link below to resolve this exception. NoUniqueBeanDefinitionException: No qualifying bean of type available: expected single matching bean but foundBeanInstantiationException: Failed to instantiate: No default constructor foundIf the default constructor is not found while auto-wiring the bean, the exception below will be thrown. org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘department’ defined in file [SpringBootBean/target/classes/com/yawintutor/Department.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yawintutor.Department]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.yawintutor.Department. If the root cause exception is displayed as No default constructor found then follow the link below to resolve this exception. BeanInstantiationException: Failed to instantiate: No default constructor foundBeanInstantiationException: Failed to instantiate: Constructor threw exceptionIf the default constructor throws an exception while auto-wiring the bean, the exception below will be thrown. org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘department’ defined in file [/SpringBootBean/target/classes/com/yawintutor/Department.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yawintutor.Department]: Constructor threw exception; nested exception is java.lang.NullPointerException If the root cause exception is displayed as Constructor threw exception then follow the link below to resolve this exception. BeanInstantiationException: Failed to instantiate: Constructor threw exceptionBeanInstantiationException: Failed to instantiate: Factory method threw exceptionIf the bean is not available, try to create and load using the abstract class name and bean factory. The beans are not going to instantiate. In this case, the exception below will be thrown. org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘animal’ defined in class path resource [com/yawintutor/SpringConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.yawintutor.AbstractAnimal]: Factory method ‘animal’ threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘abstractAnimal’ available If the root cause exception is displayed as Factory method threw exception then follow the link below to resolve this exception. BeanInstantiationException: Failed to instantiate: Factory method threw exceptionIf you find some other type of BeanCreationException, please add it to the comments section, we will provide you with the solution. What is error creating bean with name?BeanCreationException: Error creating bean with name happens when a problem occurs when the BeanFactory creates a bean. If the BeanFactory encounters an error when creating a bean from either bean definition or auto-configuration, the BeanCreationException will be thrown.
How do you fix bean instantiation through factory method failure?Solution 1
It is necessary to create a new class that extends the abstract class. If the bean factory is attempting to get the bean by using the abstract class name, it can find and associate the implemented class. The exception would then be resolved.
Why bean creation exception in Spring boot?By far, the most common cause of the BeanCreationException is Spring trying to inject a bean that doesn't exist in the context. For example, BeanA is trying to inject BeanB: @Component public class BeanA { @Autowired private BeanB dependency; ... }
Can not create bean Spring?There could be numerous reasons why Spring could not able to create a bean with name X, but clue always lies on the detailed stack trace. This error always has some underlying cause e.g. a ClassNotFoundException or a NoClassDefFoundError, which potentially signal a missing JAR file in the classpath.
|