kagkarlsson / db-scheduler

Persistent cluster-friendly scheduler for Java
Apache License 2.0
1.23k stars 188 forks source link

Spring Context not loading with lazy-init from version 14.0.1 #511

Closed michael4screen closed 1 month ago

michael4screen commented 2 months ago

Expected Behavior

Upgrade to version 14.0.1 is a patch version and does not include breaking changes.

Current Behavior

We are running spring boot integration tests with spring.main.lazy-initialization: true Context cannot be loaded anymore:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.kagkarlsson.scheduler.boot.autoconfigure.DbSchedulerAutoConfiguration': Failed to instantiate [com.github.kagkarlsson.scheduler.boot.autoconfigure.DbSchedulerAutoConfiguration$$SpringCGLIB$$0]: No default constructor found

The root cause is this change, to not eagerly load the DbSchedulerStarter: https://github.com/kagkarlsson/db-scheduler/pull/492/files


For bug reports

Context

kagkarlsson commented 2 months ago

It looks like #492 might have to be reverted @NicklasWallgren I can reproduce. Not familiar with how lazy-loading in Spring works exactly, so not sure what the fix might be.

Not sure why it would suddenly need to use the default constructor when it normally does not seem to.

NicklasWallgren commented 2 months ago

@kagkarlsson The eagerDbSchedulerStarter needs to be declared as a static method, as it's defined in the same AutoConfiguration class as the DbSchedulerStarter bean, which has a args-constructor.

My bad - it works fine in our externalized configuration (since it's in a separate configuration class with a no-args constructor). I'll open a PR.

image

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.

kagkarlsson commented 1 month ago

Ok, thanks, will have a look 👍

kagkarlsson commented 1 month ago

🎉 This issue has been resolved in v14.0.3 (Release Notes)