Spring:上下文初始化期间的ArrayIndexOutOfBoundsException

时间:2018-03-09 10:18:54

标签: spring spring-boot apache-camel

我有一个Spring-boot应用程序,它在上下文初始化期间抛出一个ArrayIndexOutOfBoundsException。这发生在春天的深处某处。

我已将原因定位到ConfigurationClassParser,方法processDeferredImportSelectors,第547行:

String[] imports = deferredImport.getImportSelector().selectImports(configClass.getMetadata());

这会调用selectImports的{​​{1}},AutoConfigurationImportSelector会调用私有方法sort,该方法将实例化 SimpleMetadataReader,这将在第65行引发异常:

classReader.accept(visitor, ClassReader.SKIP_DEBUG);

出错的资源是: SerializationDataFormatAutoConfiguration.class ,这是包org.apache.camel.impl.springboot包中的camel类。

我不确定它是否存在某种依赖性冲突,或者我的组件或 .yml 属性文件中的错误。

我的pom是:

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>nl.mycompany.camel</groupId>
 <artifactId>camel-verne-prophet-splitter</artifactId>
 <packaging>jar</packaging>
  <version>1.0.1</version>
 <name>camel-verne-prophet-splitter</name>
 <description>bla</description>
  <properties>
    <mycompany.camel.utils.version>1.46</mycompany.camel.utils.version>
    <project.mainClass>
       nl.mycompany.camel.verneprophetsplitter.StartUpVerneProphet
    </project.mainClass>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <camel.version>2.20.2</camel.version>
    <camel.jcifs.version>2.18.0</camel.jcifs.version>
    <jcifs.version>1.3.18-mycompany</jcifs.version>
    <maven.checkstyle.version>2.16</maven.checkstyle.version>
    <maven.pmd.version>3.6</maven.pmd.version>
    <target.jdk>1.8</target.jdk>
    <svnBinariesDir>forSvnBinaries</svnBinariesDir>
    <shadedResultFile>
       ${project.artifactId}-${project.version}.jar
      </shadedResultFile>
    <pitest.version>1.1.5</pitest.version>
    </properties>

       <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
 </parent>

         <dependencies>
           <dependency>
             <groupId>junit</groupId>
           <artifactId>junit</artifactId>
         <!-- Version managed by parent pom -->
        <scope>test</scope>
      </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-boot-starter</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-quartz2</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache-extras.camel-extra</groupId>
        <artifactId>camel-jcifs</artifactId>
        <version>${camel.jcifs.version}</version>
    </dependency>
    <dependency>
        <groupId>jcifs</groupId>
        <artifactId>jcifs</artifactId>
        <version>${jcifs.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-mail</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-javaconfig</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-ftp</artifactId>
        <version>${camel.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <!-- Allows the routes to be run via 'mvn camel:run' -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${target.jdk}</source>
                <target>${target.jdk}</target>
                <encoding>${project.build.sourceEncoding}</encoding>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <configuration>
                <basedPackages>
                  nl.mycompany.camel.verneprophetsplitter.config
               </basedPackages>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${maven.checkstyle.version}</version>
            <configuration>
                <configLocation>checkstyle.xml</configLocation>
                 <suppressionsLocation>
                   checkstyle-suppressions.xml
                 </suppressionsLocation>
                 <suppressionsFileExpression>
                    checkstyle.suppressions.file
                </suppressionsFileExpression>
                <includeTestSourceDirectory>true</includeTestSourceDirectory>
            </configuration>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-pmd-plugin</artifactId>
            <version>${maven.pmd.version}</version>
            <configuration>
                <linkXref>false</linkXref>
                <minimumTokens>100</minimumTokens>
                <targetJdk>${target.jdk}</targetJdk>
                <rulesets>
                    <ruleset>pmd-ruleset.xml</ruleset>
                </rulesets>
                <includeTests>true</includeTests>
            </configuration>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals>
                        <goal>check</goal>
                        <goal>cpd-check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/logback.xml</exclude>
                    <exclude>**/*.yml</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>${svnBinariesDir}</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${svnBinariesDir}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>src/main/resources</directory>
                                <includes>
                                    <include>*.*</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                            <resource>
                                <directory>target</directory>
                                <includes>
                                    <include>${shadedResultFile}</include>
                                </includes>
                            </resource>
                            <resource>
                                <directory>${basedir}</directory>
                                <includes>
                              <include>StartVerneProphetSplitter.*</include>
                                </includes>
                                <filtering>true</filtering>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.pitest</groupId>
            <artifactId>pitest-maven</artifactId>
            <version>${pitest.version}</version>
            <configuration>
                <timestampedReports>false</timestampedReports>
                <reportsDirectory>pitest_reports</reportsDirectory>
                <targetClasses>
                    <param>nl.mycompany.camel.verneprophetsplitter.*</param>
                </targetClasses>
                <targetTests>
                    <param>nl.mycompany.camel.verneprophetsplitter.*</param>
                </targetTests>
                <jvmArgs>
                    <value>-Xmx512m</value>
                    <value>-XX:MaxPermSize=128m</value>
                </jvmArgs>
                <timeoutConstant>20000</timeoutConstant>
                <historyInputFile>pitests/history</historyInputFile>
                <historyOutputFile>pitests/history</historyOutputFile>
            </configuration>
        </plugin>
    </plugins>
</build>

 <reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-maven-plugin</artifactId>
            <configuration>
                <finalName>camel-verne-prophet-splitter</finalName>
                <outputDirectory>target</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
 </reporting>
</project>

我的application.yml只是:

from: from
to: to

我的配置类是:

package nl.mycompany.camel.verneprophetsplitter.config;

 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Configuration;

 /**
  * Configuration for the verne-prophet application.
  *
  */
  @Configuration
  @ConfigurationProperties
  public class ApplicationConfig {

   private String from;
   private String to;


   /**
    * @return the from
    */
   public String getFrom() {
       return from;
   }

   /**
    * @param aFrom the from to set
    */
   public void setFrom(String aFrom) {
       from = aFrom;
   }

   /**
    * @return the to
    */
   public String getTo() {
       return to;
   }

   /**
   * @param aTo the to to set
   */
   public void setTo(String aTo) {
      to = aTo;
   }


}

2 个答案:

答案 0 :(得分:1)

我第一次使用Spring Boot 2.0时没有发现。

Apache Camel与Spring Boot 2不兼容,您必须使用Spring Boot 1.5.x。

计划在2018年夏季推出的Apache Camel 2.22版本中支持Spring Boot 2.

答案 1 :(得分:0)

基于answer和Claus Ibsen的评论,我设法使用版本1.5.10.RELEASE的Spring-boot和2.18.0的驼峰。

此外,eclipse似乎有一个并不总是更新的缓存。 处理这类问题的最有效方法似乎是与maven的命令行。首先让它运行,在尝试不同的版本组合之间使用mvn clean eclipse:clean eclipse:eclipsemvn install