org.springframework.beans.factory.BeanDefinitionStoreException无法读取候选组件类

时间:2019-02-19 08:53:21

标签: spring-boot maven-plugin

我读过类似的post,但仍然无法解决此问题。我正在使用JDK 8和Spring5。所以不是由于版本问题。

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [G:\githome\product-aggregation\target\classes\com\roger\product\ipc\viewobject\product\MultiUnitVO.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 90
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:454)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:275)
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:288)

Caused by: java.lang.ArrayIndexOutOfBoundsException: 90
at org.springframework.asm.ClassReader.readUTF(ClassReader.java:2646)
at org.springframework.asm.ClassReader.readUTF8(ClassReader.java:2618)
at org.springframework.asm.ClassReader.readMethod(ClassReader.java:1110)
at org.springframework.asm.ClassReader.accept(ClassReader.java:729)
at org.springframework.asm.ClassReader.accept(ClassReader.java:527)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:65)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430)
... 20 common frames omitted

就是这样。我开发了一个maven插件,并将其包含在我的项目中。此插件用于在过程类阶段为特定类生成字段。为此,我使用了ASM(5.0版)来修改类。像这样的Maven依赖项:

<dependencies>
<dependency>
  <groupId>org.apache.maven</groupId>
  <artifactId>maven-plugin-api</artifactId>
  <version>2.0</version>
</dependency>
<dependency>
  <groupId>com.roger</groupId>
  <artifactId>permission</artifactId>
  <version>1.0-SNAPSHOT</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
  <groupId>commons-io</groupId>
  <artifactId>commons-io</artifactId>
  <version>2.6</version>
</dependency>
<dependency>
  <groupId>javassist</groupId>
  <artifactId>javassist</artifactId>
  <version>3.12.1.GA</version>
</dependency>
<dependency>
  <groupId>org.apache.maven.plugin-tools</groupId>
  <artifactId>maven-plugin-annotations</artifactId>
  <version>3.2</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>org.codehaus.plexus</groupId>
  <artifactId>plexus-utils</artifactId>
  <version>3.0.8</version>
</dependency>
<dependency>
  <groupId>org.ow2.asm</groupId>
  <artifactId>asm</artifactId>
  <version>5.0</version>
</dependency>
<dependency>
  <groupId>org.ow2.asm</groupId>
  <artifactId>asm-tree</artifactId>
  <version>5.0</version>
</dependency>

然后我将其包含在我的项目中。

 <plugin>
    <groupId>com.roger</groupId>
    <artifactId>authorization-maven-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <executions>
      <execution>
        <id>execution1</id>
        <phase>process-classes</phase>
        <goals>
          <goal>addFieldPermission</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

我的项目还间接依赖于ASM(版本5.0.4)。我什至将ASM升级到5.0.4(与项目相同),仍然出错。

Dependency popup

我怀疑这是由于ASM冲突引起的,但不知道如何解决。有想法吗?

编辑似乎是修改后的类有问题。我调试了ClassPathScanningCandidateComponentProvider(spring-context-5.0.8),发现从行430抛出的异常仅用于修改后的资源(正如我说的,我通过maven插件在其中添加了一些字段)。但是我使用javap反编译了修改后的类,并发现它是有效的。我猜修改后的类有问题,但不知道是什么问题。

2 个答案:

答案 0 :(得分:0)

如错误日志中所述,这是超出范围的明确索引。

  

原因:java.lang.ArrayIndexOutOfBoundsException:90

答案 1 :(得分:0)

最后,我得到了一个临时解决方案。我公开了这些字段,并删除了生成的方法,一切顺利。

生成的方法是根本原因。当我仅保留生成的字段时,Spring Boot成功启动。似乎javassist 3.12.1.GA在JDK 1.8中可能出错。我将进一步调查。