'Bean Definition Overriding disabled in Spring Boot 2.X.X

As you know since Spring Boot 2.X.X., Bean Definition Overriding is disabled by default. Please click here for more description on that topic in the release notes.

I am trying to migrate from Spring Boot 1.5 to Spring Boot 2.6.4 and (logically) my test fails with very same exception. The exception is absolutely the same for all tests that failed.

java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException at DefaultListableBeanFactory.java:1004

OK, fine!

However, when I try to apply the solution provided by Spring guys themselves i.e. adding spring.main.allow-bean-definition-overriding=true in my the sub-project's (which test fails) src/main/resources/application.properties file, all the same test failed one more time (absolutely same test as before change) again - with same exception, which in this case is

java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
            Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at AutowiredAnnotationBeanPostProcessor.java:767
                Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException at ConstructorResolver.java:800
                    Caused by: org.springframework.boot.context.properties.ConfigurationPropertiesBindException at ConfigurationPropertiesBindingPostProcessor.java:92
                        Caused by: org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException at ConfigurationPropertyName.java:612

Honestly, I have no idea, what is going on and any help will be appreciated !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source