Skip to content

Commit

Permalink
#2272 Do not fail in startup time if LockProvider is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Nov 25, 2024
1 parent 8be6ffd commit ba49299
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.lang.reflect.Method;
import net.javacrumbs.shedlock.core.LockProvider;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;

/**
* Not public now. If you think you need your LockProviderSupplier please create an issue and explain your use-case.
Expand All @@ -15,10 +14,10 @@ interface LockProviderSupplier {
static LockProviderSupplier create(ListableBeanFactory beanFactory) {
// Only fetching beanNames as the beans might not have been initialized yet.
String[] beanNamesForType = beanFactory.getBeanNamesForType(LockProvider.class);
if (beanNamesForType.length == 0) {
throw new NoSuchBeanDefinitionException(LockProvider.class, "No LockProvider bean found.");
}
if (beanNamesForType.length == 1) {
// If there are no beans of LockProvider type, we can't fail here as in older version we
// did not fail, and it's quire common in tests. To maintain backward compatibility
// the failure will happen in runtime.
if (beanNamesForType.length <= 1) {
return (target, method, arguments) -> beanFactory.getBean(LockProvider.class);
}
return new BeanNameSelectingLockProviderSupplier(beanFactory);
Expand Down

0 comments on commit ba49299

Please sign in to comment.