Stange behaviour since upgrade from 2.6.2 to 2.7.0

Viewed 130

I faced to a strange behaviour while upgrading my application from SpringBoot 2.6.2 to 2.7.0. I've a starter with autoconfiguration which is responsible of initializing JPA auditing :

@Configuration
@ConditionalOnBean(DataSource.class)
@ConditionalOnClass({DataSource.class, AuditorAware.class, SecurityContextHolder.class})
@AutoConfigureAfter({HibernateJpaAutoConfiguration.class, SecurityAutoConfiguration.class, ClockSpringConfiguration.class})
@EnableJpaAuditing(auditorAwareRef = "auditorProvider", dateTimeProviderRef = "dateTimeProvider")
public class JpaAuditingSpringConfiguration {
    @Bean
    public AuditorAware<String> auditorProvider() {
        return () ->
                Optional.ofNullable(SecurityContextHolder.getContext())
                        .map(SecurityContext::getAuthentication)
                        .map(Authentication::getName);
    }

    @Bean
    public DateTimeProvider dateTimeProvider(Clock clock) {
        return () ->
                Optional.of(clock)
                        .map(Clock::instant);
    }
}

This starter is fine in 2.6.2. But in 2.7.0 the @ConditionalOnBean(DataSource.class) avoid the starter to perform initialization. When i remove the statement all is fine again.

I don't understand why it doesn't work since the update? Maybe i misused or forgot some statement. The behaviour i attempt to is the autoconfiguration apply only if a datasource bean is registred.

If someone can help me ?

PS : sorry for my english :-)

1 Answers

So i found the solution, it was a mistake from myself... I put the @AutoConfigureAfter on a @Configuration imported by the autoconfiguration entrypoint. So i move the statement on the autoconfiguration class and now all is fine. The new annotation @AutoConfiguration will be very usefull to avoid this kinf of mistake.

Related