Spring Boot 2上的Java BeanDefinitionStoreException

时间:2019-06-26 18:23:45

标签: java spring-boot

我正在尝试使用Spring Boot 2(特别是2.1.5.RELEASE)重写应用程序。先前版本使用1.5.7.RELEASE。我们正在切换数据库平台,因此进行了重写。新旧的启动类几乎相同,都试图从另一个库创建一个bean。它可以在1.5.7中工作,但在2.1.5中却失败,并显示以下消息:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process 
import candidates for configuration class [com.company.consumer.ConsumerRecoveryConfiguration];
 nested exception is java.lang.IllegalStateException: Failed to introspect
annotated methods on class com.company.consumer.RecordRecovery

这是新旧启动类的外观:

旧:

@SpringBootApplication
@ComponentScan(basePackages = {
    "com.company.core",
    "com.company.something",
    "com.company.platform",
    "com.company.config"},
    excludeFilters = @ComponentScan.Filter(type =
        FilterType.REGEX, pattern = "com.company.common.diag.*"))
@Import({SomeClass.class, ConsumerRecoveryConfiguration.class,
    ConsumerRetryConfiguration.class})
@PropertySource("classpath:build.properties")
public class SomeApplication {

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

  @Bean(name = "someDbTimingLogger")
  public TimingLogger getSomeDbTimingLogger() {
    return new TimingLogger(LoggerFactory.getLogger("timing.someDb"));
  }

  @Bean(name = "timingLogger")
  public TimingLogger getTimingLogger() {
    return new TimingLogger(LoggerFactory.getLogger("timing.consumer"));
  }

  @Bean(name = "kafkaTimingLogger")
  public TimingLogger getKafkaTimingLogger() {
    return new TimingLogger(LoggerFactory.getLogger("timing.kafka"));
  }

  @Bean(name = "parser")
  public Parser<GenericMessageModel> getSomeModelParser() {
   return new Parser<>(GenericMessageModel.class);
  }
}

新功能:

@SpringBootApplication
@ComponentScan(basePackages = {
    "com.company.core",
    "com.company.something",
    "com.company.platform",
    "com.company.config"},
    excludeFilters = @ComponentScan.Filter(
            type = FilterType.REGEX,
            pattern = "com.company.common.diag.*"
    ))
@Import({ ConsumerRecoveryConfiguration.class,
        ConsumerRetryConfiguration.class })
@PropertySource("classpath:build.properties")
public class SomeApplication {

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

    @Bean(name = "timingLogger")
    public TimingLogger getTimingLogger() { return new TimingLogger(LoggerFactory.getLogger("timing.consumer")); }

    @Bean(name = "kafkaTimingLogger")
    public TimingLogger getKafkaTimingLogger() { return new TimingLogger(LoggerFactory.getLogger("timing.kafka")); }

    @Bean(name = "parser")
    public Parser<GenericMessageModel> getSomeModelParser() { return new Parser<>(GenericMessageModel.class, null); }
}

嵌套异常中提到的Kotlin类如下(减去其众多的私有方法):

@Component
class RecordRecovery(val producer: KafkaProducer<String, String>, val kafkaProducerSettings: KafkaProducerSettings,
                     val recoverySettings: RecoverySettings, val objectMapper: ObjectMapper) {

    val random = ThreadLocalRandom.current()!!


    companion object {
        val LOGGER = LoggerFactory.getLogger(RecordRecovery::class.java)
    }

    fun recoverRecords(records: ConsumerRecords<String, String>, exception: Exception) {
        recoverRecords(records.map { it.value() ?: StringUtils.EMPTY }, exception)
    }

    fun recoverRecords(records: List<Any>, exception: Exception) {
        error(metaDataFor(records.count()), LOGGER, "Recovering {} records", records.count())
        val filteredRecords = records.map {  createRecoveryRecord(it) }
                .filter{ it != null }
                .map { recordToJson(it) }
                .filter { removeNulls(it) }
                .mapIndexed { index, it -> toEmergencyDataWrapper(it!!, exception, index) }
                .mapNotNull {toJSONStringOrNull(it)}
                .map {toProducerRecord(it)}
                .map { republish(it) }
                .toList()
        info(metaDataFor(filteredRecords.count()), LOGGER, "After filtering, recovering {} records", filteredRecords.count())
        filteredRecords.map { await(it) }
    }
}

这是有问题的ConsumerRecoveryConfiguration类(也是Kotlin):

@Configuration
@Import(KafkaProducerConfig::class, RecoverySettings::class, RecordRecovery::class)
class ConsumerRecoveryConfiguration

该班级没有任何身体。我假设导入其他类会使Spring基本上将那些用作主体。

在谈到Spring时,我还是有点绿,所以我很难理解为什么当我更改为SB 2时它停止工作了。关于我应该看什么或有什么帮助我解决这个问题的任何建议? / p>

编辑:

这是请求的完整堆栈跟踪:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.company.consumer.ConsumerRecoveryConfiguration]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.company.consumer.RecordRecovery
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:596)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:302)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:586)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:302)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at com.company.SomeApplication.main(SomeApplication.java:35)
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.company.consumer.RecordRecovery
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:169)
    at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:392)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:317)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:586)
    ... 20 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/json/JSONObject
    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.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:158)
    ... 24 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.json.JSONObject
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 28 common frames omitted

0 个答案:

没有答案