NoClassDefFoundError: net/javacrumbs/shedlock/core/LockProvider

2.9k Views Asked by At

We try to develop a cron batch . I configured a @SchedulerLock anotation but these not work. This code probabably work with more than 1 node. I read in Github that @SchedulerLock may work with these implement, but not work. I tried too , @TryLock but dosent work too. I need help to run these code because i don't know what is the failure in code. Thanks!

@SpringBootApplication
@EnableAutoConfiguration
@EnableCaching
public class AppExportacionDatos {

    public static void main(String[] args) {
        SpringApplication.run(AppExportacionDatos.class, args);
    }

}

@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "540m")
public class CommonConfig {
    
    @Bean
    public LockProvider lockProvider(DataSource dataSource) {
        return new JdbcTemplateLockProvider(
            JdbcTemplateLockProvider.Configuration.builder()
            .withJdbcTemplate(new JdbcTemplate(dataSource))
            .usingDbTime() // Works on Postgres, MySQL, MariaDb, MS SQL, Oracle, DB2, HSQL and H2
            .build()
        );
    }
    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:i18n/messages");
        messageSource.setDefaultEncoding("ISO-8859-1");
        return messageSource;
    }
    @Bean
    public LocalValidatorFactoryBean getValidator() {
        LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
        bean.setValidationMessageSource(messageSource());
        return bean;
    }

}
@Component
public class BatchTasks {

    
//  @Scheduled(cron = "${cronExpression}")
    @Scheduled(fixedDelay = 60000)
    @SchedulerLock(name = "scheduledTaskName") 
    public void generarFicheroExportacion() {
        ................
    }
}

        <dependency>
            <groupId>net.javacrumbs.shedlock</groupId>
            <artifactId>shedlock-spring</artifactId>
            <version>4.20.0</version>
        </dependency>
        <dependency>
            <groupId>net.javacrumbs.shedlock</groupId>
            <artifactId>shedlock-provider-jdbc-template</artifactId>
            <version>4.20.0</version>
        </dependency>

The exception wen run the app are:

Caused by: java.lang.ClassNotFoundException: net.javacrumbs.shedlock.core.LockProvider
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_281]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[?:1.8.0_281]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) ~[?:1.8.0_281]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_281]
    at java.lang.Class.forName0(Native Method) ~[?:1.8.0_281]
    at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_281]
    at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:144) ~[spring-boot-devtools-2.4.0.jar:2.4.0]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[?:1.8.0_281]
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:1.8.0_281]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[?:1.8.0_281]
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[?:1.8.0_281]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.1.jar:5.3.1]
    ... 26 more

0

There are 0 best solutions below