bladex-boot 引入springBatch失败

Blade 未结 2 1279
18695658335
18695658335 2021-07-11 19:20
悬赏:5

一、该问题的重现步骤是什么?

1. pom引入

        -->
            org.springframework.boot
            spring-boot-starter-batch
        -->

2. 在Application启动类配置

@EnableBatchProcessing

yml下配置
spring:
  batch:
    job:
      enabled: false

3.我把application.yml里的druid配置注释了,不知道会不会产生什么别的影响,想采用默认的HikariCP ,但是无论我注释还是不注释,启动都是失败的

image.pngimage.png

二、你期待的结果是什么?实际看到的又是什么?

程序正常启动,实际启动失败


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladex-boot 2.8.1 RELEASE mac操作系统

四、请提供详细的错误堆栈信息,这很重要。

java.lang.IllegalStateException: Error processing condition on org.springblade.core.context.config.BladeContextAutoConfiguration.bladeHttpHeadersGetter

at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)

at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)

at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:184)

at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:144)

at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)

at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)

at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)

at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)

at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)

at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:707)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533)

at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)

at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)

at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)

at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)

at org.springblade.core.launch.BladeApplication.run(BladeApplication.java:50)

at org.springblade.Application.main(Application.java:36)

Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.redisson.spring.cache.RedissonCacheStatisticsAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)

at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)

at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742)

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648)

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495)

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:238)

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:231)

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:221)

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:169)

at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:144)

at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)

... 17 common frames omitted

Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/actuate/metrics/cache/CacheMeterBinderProvider

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:763)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)

at java.net.URLClassLoader.access$100(URLClassLoader.java:73)

at java.net.URLClassLoader$1.run(URLClassLoader.java:368)

at java.net.URLClassLoader$1.run(URLClassLoader.java:362)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:361)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

at java.lang.Class.getDeclaredMethods0(Native Method)

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)

at java.lang.Class.getDeclaredMethods(Class.java:1975)

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)

... 33 common frames omitted

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 49 common frames omitted


2021-07-11 19:17:58.695  WARN 22194 --- [           main] o.s.boot.SpringApplication               : Unable to close ApplicationContext


java.lang.IllegalStateException: Failed to introspect Class [org.redisson.spring.cache.RedissonCacheStatisticsAutoConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)

at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358)

at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:742)

at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:741)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:680)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:648)

at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1614)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:523)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:495)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:620)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:612)

at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1243)

at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:869)

at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:857)

at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:844)

at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:795)

at org.springframework.boot.SpringApplication.run(SpringApplication.java:325)

at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)

at org.springblade.core.launch.BladeApplication.run(BladeApplication.java:50)

at org.springblade.Application.main(Application.java:36)

Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/actuate/metrics/cache/CacheMeterBinderProvider

at java.lang.ClassLoader.defineClass1(Native Method)

at java.lang.ClassLoader.defineClass(ClassLoader.java:763)

at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)

at java.net.URLClassLoader.access$100(URLClassLoader.java:73)

at java.net.URLClassLoader$1.run(URLClassLoader.java:368)

at java.net.URLClassLoader$1.run(URLClassLoader.java:362)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:361)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

at java.lang.Class.getDeclaredMethods0(Native Method)

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)

at java.lang.Class.getDeclaredMethods(Class.java:1975)

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463)

... 21 common frames omitted

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 37 common frames omitted


2条回答
  •  admin
    admin (楼主)
    2021-07-13 14:07

    你用了这么久,应该要有自行排查的能力了,我来和你说怎么做。

    一、首先看报错:

    Caused by: java.lang.ClassNotFoundException: org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider

    意思是没有 CacheMeterBinderProvider 这个类,那么你就去百度查一下这个类在哪里

    二、找到CacheMeterBinderProvider在spring-actuator,那么就加上对应依赖

    
        org.springframework.boot
        spring-boot-starter-batch
    
    
        org.springframework.boot
        spring-boot-starter-actuator
    

    三、启动工程,发现会有如下报错

    Caused by: java.sql.SQLSyntaxErrorException: Table 'bladex_boot.BATCH_JOB_INSTANCE' doesn't exist

    四、再次百度,发现需要加一段配置

    spring:
      batch:
        initialize-schema: always

    五、Application加测试代码

    @EnableBatchProcessing
    @EnableScheduling
    @SpringBootApplication
    @AllArgsConstructor
    public class Application {
    
       private final JobBuilderFactory jobBuilderFactory;
    
       private final StepBuilderFactory stepBuilderFactory;
    
       @Bean
       public Step step() {
          return this.stepBuilderFactory.get("step1")
             .tasklet((contribution, chunkContext) -> {
                System.out.println("Hello, World!");
                return RepeatStatus.FINISHED;
             }).build();
       }
    
       @Bean
       public Job job() {
          return this.jobBuilderFactory.get("job")
             .start(step())
             .build();
       }
    
       public static void main(String[] args) {
          BladeApplication.run(CommonConstant.APPLICATION_NAME, Application.class, args);
       }
    
    }

    六、启动成功,解决整个过程不需要花5分钟,希望以后遇到问题可以多思考多搜索,不要以为无法启动就是框架本身的问题,也不要直接丢群里等着其他人帮忙,这样等待会浪费很多时间。

    image.png

    image.png

    image.png


提交回复