'jpaAuditingHandler' defined in null on application startup using spring boot

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