After upgrading to spring boot 2.1 from 2.0.5, I am getting following error at application start up:
The bean 'jpaAuditingHandler', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.
The error gets resolved if I specify following in application.yaml:
spring:
main:
allow-bean-definition-overriding: true
What will this allow-bean-definition-overriding do ?
Also, I don't want to do enable that. How can I configure 'jpaAuditingHandler' to get away with this error
You will get this error if you have multiple @EnableJpaAuditing
declarations in your Spring config files. Just declare it once.
I developed a library, which required @EnableJpaAuditing
. Users could have their own @Configuration
classes, which could be declaring @EnableJpaAuditing
. This would be leading to application context failure because of multiple @EnableJpaAuditing
in one context.
So, we had to declare @EnableJpaAuditing
only if the user context has not already declared it.
Fortunately, the Spring Boot allows conditions at context.
Next solution (in Kotlin) is the @Configuration
, which is applied only if @EnableJpaAuditing
was not applied.
@Configuration
@ConditionalOnMissingBean(name=["jpaAuditingHandler"])
@EnableJpaAuditing
class JpaAuditingNonConflictingDeclaration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With