V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
chenguoyu
V2EX  ›  Java

求教一个 springcloud Finchley.SR2 一个很奇怪的问题, ArrayStoreException

  •  
  •   chenguoyu · 2018-11-19 08:25:45 +08:00 · 1302 次点击
    这是一个创建于 2229 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringRunner;
    
    @RunWith(SpringRunner.class)
    @SpringBootTest
    public class UserServiceApplicationTests {
    
        @Test
        public void contextLoads() {
            System.out.println(111111);
        }
    
    }
    

    一个最简单的,甚至是 maven 生成的代码,在运行的时候报错

    java.lang.IllegalStateException: Failed to load ApplicationContext
    
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
    	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
    	at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
    	at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
    	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
    	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780)
    	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
    	at org.springframework.boot.SpringApplication.run(SpringApplication.java:333)
    	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139)
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    	... 24 more
    Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
    	at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
    	at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
    	at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
    	at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
    	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
    	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
    	at java.lang.Class.createAnnotationData(Class.java:3521)
    	at java.lang.Class.annotationData(Class.java:3510)
    	at java.lang.Class.createAnnotationData(Class.java:3526)
    	at java.lang.Class.annotationData(Class.java:3510)
    	at java.lang.Class.getAnnotation(Class.java:3415)
    	at java.lang.reflect.AnnotatedElement.isAnnotationPresent(AnnotatedElement.java:258)
    	at java.lang.Class.isAnnotationPresent(Class.java:3425)
    	at org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation(AnnotatedElementUtils.java:570)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.isHandler(RequestMappingHandlerMapping.java:177)
    	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:218)
    	at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:189)
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:136)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695)
    	... 39 more
    
    
    5 条回复    2018-11-19 12:56:42 +08:00
    lil460982475
        1
    lil460982475  
       2018-11-19 08:57:16 +08:00   ❤️ 1
    1. 这个跟 springcloud 没关系
    2. 猜测应该是你 springmvc 的注解写的有问题,异常堆栈出现了 RequestMappingHandlerMapping 和 AnnotatedElementUtils,说明是 springmvc 的注解解析问题。检查下自己代码吧,EnableWebMvcConfiguration 这个配置类?
    chenguoyu
        2
    chenguoyu  
    OP
       2018-11-19 09:09:01 +08:00
    @lil460982475 可是我用的是 springboot 自动配置的配置啊,并没有写自己的配置类
    Antihank
        3
    Antihank  
       2018-11-19 09:33:02 +08:00   ❤️ 1
    //@RunWith(SpringRunner.class)
    干掉这个注解
    ourslay
        4
    ourslay  
       2018-11-19 10:21:00 +08:00   ❤️ 1
    pom.xml 发上来看看看
    chenguoyu
        5
    chenguoyu  
    OP
       2018-11-19 12:56:42 +08:00
    @ourslay 感谢,找到原因了,确实是 pom 的问题,我把打包方式写成 pom 了,导致的问题
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2737 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:22 · PVG 23:22 · LAX 07:22 · JFK 10:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.