How to set spring.main.allow-bean-definition-overriding to true in a Spring boot 2.1.0 starter configuration
Spring Boot's ErrorAttributes
bean is defined by ErrorMvcAutoConfiguration
. It is annotated with @ConditionalOnMissingBean
so it will back off if an ErrorAttributes
bean has already been defined. As the bean defined by your ErrorsConfig
class is attempting to override Boot's ErrorAttributes
bean rather than causing it to back off, your ErrorsConfig
class must be getting processed after Boot's ErrorMvcAutoConfiguration
class. This means that you have an ordering problem in your starter.
The order in which auto-configuration classes are processed can be controlled using @AutoConfigureBefore
and @AutoConfigureAfter
. Assuming that ErrorsConfig
is itself an auto-configuration class registered in spring.factories
, you can fix your problem by annotating it with @AutoConfigureBefore(ErrorMvcAutoConfiguration.class)
. With this change in place ErrorsConfig
will define its ErrorAttributes
bean before ErrorMvcAutoConfiguration
attempts to do so which will cause the auto-configuration of Boot's ErrorsAttribute
bean to back off.
you can paste this command"spring.main.allow-bean-definition-overriding=true"
in the workspace/project/src/main/resources/applicationproperties edit the file and paste the command and run your project in debug mode.