Skip to content

Commit

Permalink
fix: 511 - Declare DbSchedulerAutoConfiguration#eagerDbSchedulerStart…
Browse files Browse the repository at this point in the history
…er as static (#512)

The `DbSchedulerAutoConfiguration#eagerDbSchedulerStarter` must be
declared as static to ensure it is available before the `initialization`
of `DbSchedulerAutoConfiguration`. Spring Boot will otherwise try to
instantiate the `DbSchedulerAutoConfiguration` class using a no-args
constructor.

> NOTE: Beans of this type will be instantiated very early in the spring
application lifecycle so they should generally be declared static and
not have any dependencies.


https://docs.spring.io/spring-boot/api/java/org/springframework/boot/LazyInitializationExcludeFilter.html#:~:text=NOTE%3A%20Beans%20of%20this%20type%20will%20be%20instantiated%20very%20early%20in%20the%20spring%20application%20lifecycle%20so%20they%20should%20generally%20be%20declared%20static%20and%20not%20have%20any%20dependencies.

Example - auto-configuration class with an args-constructor;

https://github.com/spring-projects/spring-boot/blob/ef303e74f7b92373e32d1cf95a121b37d377960a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java#L116

Fixes #511

## Reminders
- [ ] Added/ran automated tests
- [ ] Update README and/or examples
- [X] Ran `mvn spotless:apply`

---
cc @kagkarlsson
  • Loading branch information
NicklasWallgren authored Jul 23, 2024
1 parent 679332b commit e11e04e
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public DbSchedulerStarter dbSchedulerStarter(Scheduler scheduler) {
}

@Bean
public LazyInitializationExcludeFilter eagerDbSchedulerStarter() {
static LazyInitializationExcludeFilter eagerDbSchedulerStarter() {
return LazyInitializationExcludeFilter.forBeanTypes(DbSchedulerStarter.class);
}

Expand Down

0 comments on commit e11e04e

Please sign in to comment.