Spring4 Failed to read candidate component class 问题


使用 spring 4 搭建环境时报以下错误


 Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:/Users/darren/.m2/repository/com/chejingji/monitor/monitor-dal/1.0/monitor-dal-1.0.jar!/com/chejingji/monitor/dal/mongo/dao/UserDAO.class]; nested exception is java.lang.ArrayIndexOutOfBoundsException: 828
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:303)
    at org.springframework.data.repository.config.RepositoryComponentProvider.findCandidateComponents(RepositoryComponentProvider.java:121)
    at org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.getCandidates(RepositoryConfigurationSourceSupport.java:70)
    at org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport.getRepositoryConfigurations(RepositoryConfigurationExtensionSupport.java:85)
    at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:126)
    at org.springframework.data.repository.config.RepositoryBeanDefinitionParser.parse(RepositoryBeanDefinitionParser.java:71)
    ... 63 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 828
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:183)
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:153)
    at org.springframework.asm.ClassReader.<init>(ClassReader.java:426)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:53)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:93)
    at org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter.match(AbstractTypeHierarchyTraversingFilter.java:121)
    at org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter.match(AbstractTypeHierarchyTraversingFilter.java:105)
    at org.springframework.data.repository.config.RepositoryComponentProvider$InterfaceTypeFilter.match(RepositoryComponentProvider.java:187)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.isCandidateComponent(ClassPathScanningCandidateComponentProvider.java:346)
    at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:280)

jar 包依赖关系为:


 [INFO] com.chejingji.monitor:monitor-web:war:1.0
[INFO] +- com.chejingji.monitor:monitor-common:jar:1.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.4.RELEASE:compile
[INFO] |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.4.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-oxm:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-jdbc:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-webmvc:jar:4.1.4.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.1.4.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-test:jar:4.1.4.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-mongodb:jar:1.6.1.RELEASE:compile
[INFO] |  |  \- org.springframework.data:spring-data-commons:jar:1.9.1.RELEASE:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.3:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] |  +- org.apache.httpcomponents:httpclient-cache:jar:4.3:compile
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.3:compile
[INFO] |  +- org.mybatis:mybatis:jar:3.2.4:compile
[INFO] |  +- org.mybatis:mybatis-spring:jar:1.2.2:compile
[INFO] |  +- mysql:mysql-connector-java:jar:5.1.34:compile
[INFO] |  +- com.alibaba:druid:jar:1.0.2:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.4.0:compile
[INFO] |  +- log4j:log4j:jar:1.2.16:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.1:compile
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.1:compile
[INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.7.1:compile
[INFO] |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] |  +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  \- commons-lang:commons-lang:jar:2.4:compile
[INFO] |  +- velocity-tools:velocity-tools-generic:jar:1.2:compile
[INFO] |  +- velocity-tools:velocity-tools:jar:1.4:compile
[INFO] |  +- com.alibaba:fastjson:jar:1.1.15:compile
[INFO] |  \- org.mongodb:mongo-java-driver:jar:2.12.4:compile
[INFO] +- com.chejingji.monitor:monitor-dal:jar:1.0:compile
[INFO] +- com.chejingji.monitor:monitor-biz:jar:1.0:compile
[INFO] \- junit:junit:jar:4.11:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test

spring 配置文件为:


 <mongo:mongo id="mongo"  host="$!{mongodb_host}" port="${mongodb_port}" />

    <bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials">
        <constructor-arg name="username"  value="$!{mongodb_username}"/>
        <constructor-arg name="password"  value="$!{mongodb_password}"/>
    </bean>

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg ref="mongo" />
        <constructor-arg value="$!{mongodb_database}" />
        <constructor-arg ref="userCredentials" />
    </bean>

    <mongo:mapping-converter base-package="com.chejingji.monitor.dal.mongo.entity"/>

    <mongo:repositories base-package="com.chejingji.monitor.dal.mongo.dao"/>

jdk 使用 1.8,求助各位大牛!!

spring spring-mvc java

6yecao 9 years, 12 months ago

这是个比较诡异的错误
Caused by: java.lang.ArrayIndexOutOfBoundsException: 828
at org.springframework.asm.ClassReader.(ClassReader.java:183)

我翻了下源代码,是在解析class文件时越出了class的长度。

请检查下这个文件
jar:file:/Users/darren/.m2/repository/com/chejingji/monitor/monitor-dal/1.0/monitor-dal-1.0.jar 里面的 com/chejingji/monitor/dal/mongo/dao/UserDAO.class

每逢寂寞倍思春 answered 9 years, 12 months ago

从dependency tree似乎看不出问题,题主试试清理.m2并重新install。

家具屋店长 answered 9 years, 12 months ago

Your Answer