java – 无法在ClassReader中加载由ArrayIndexOutOfBoundsException引起的ApplicationContext

前端之家收集整理的这篇文章主要介绍了java – 无法在ClassReader中加载由ArrayIndexOutOfBoundsException引起的ApplicationContext前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

当我运行junit测试类时,出现以下异常?我该如何解决这个问题?

Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 8
    at org.springframework.asm.ClassReader.readUnsignedShort(Unknown Source)
    at org.springframework.asm.ClassReader.MetadataReader.MetadataReader.java:48)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
    at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
    at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
    at org.springframework.context.annotation.ConfigurationClassUtils.checkConfigurationClassCandidate(ConfigurationClassUtils.java:70)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:233)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:203)
    at org.springframework.context.support.AbstractApplicationContext.invokebeanfactoryPostProcessors(AbstractApplicationContext.java:617)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
    at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)

我的考试班是

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:dispatcher-servlet.xml")

public class CandidateDAOImplTest{
@Autowired
    public CandidateDAO candidateService;


    @Test
    public void testGetCandidate() {...}
}

调度员servlet.xml中

它位于web / WEB-INF / dispatcher-servlet.xml.
我正在使用netbeams ied 7.3和glassfish server 3.0

最佳答案
很可能你的一个spring bean里面有lambda表达式.显然,如果代码中有某个lambda,则spring 3 beans无法初始化.如果不能选择迁移到spring 4,请尝试使用匿名类重写lambda表达式,例如

Function

或者将lambda代码移出spring bean.我有同样的问题,它帮助了我,我仍然可以使用jre / jdk 8的spring 3.

避免这种失败:

 Caused by: java.lang.ArrayIndexOutOfBoundsException: 10348
    at org.springframework.asm.ClassReader.
原文链接:https://www.f2er.com/spring/431803.html

猜你在找的Spring相关文章