Springboot项目出现java.lang.ArrayStoreException的异常分析
参考文献:https://www.jb51.net/article/232858.htm
使用springboot 2 构建项目,调试代码的时候出现了如下的报错信息
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.TypeNotPresentExceptionProxyat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1708)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:581)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503)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.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1325)at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1291)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1193)at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1096)at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)... 36 common frames omittedCaused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxyat 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:573)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.isHandler(RequestMappingHandlerMapping.java:177)at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:217)at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.afterPropertiesSet(AbstractHandlerMethodMapping.java:188)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.afterPropertiesSet(RequestMappingHandlerMapping.java:129)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704)... 50 common frames omitted
第一眼看到这个问题的时候感觉头都比较大,那只能调试断定,新建一个断点,类型是Java Exception Breakpoint,异常类是上面抛出来的java.lang.ArrayStoreException,
通过调试查看是找不到org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration这个类,而AnnotationParser.parseClassValue把异常包装成为Object,然后在sun.reflect.annotation.AnnotationParser.parseClassArray(int, ByteBuffer, ConstantPool, Class
result[i] = parseClassValue(buf, constPool, container);
而这里数组越界了,ArrayStoreException只有越界的Object的类型信息,也就是上面的
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
发现是java.lang.ClassNotFoundException: org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration,则加上@ConditionalOnClass的检查就可以了.
准确来说是spring boot2把一些类的package改了:spring boot 1里类名是:
- org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
- org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration
【Springboot项目出现java.lang.ArrayStoreException的异常分析】以上所述是小编给大家介绍的Springboot项目出现java.lang.ArrayStoreException的异常分析,希望对大家有所帮助。在此也非常感谢大家对脚本之家网站的支持!
推荐阅读
- Activiti(一)SpringBoot2集成Activiti6
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- 17|17 关山松 第二课作业#公众号项目# D20
- RxJava|RxJava 在Android项目中的使用(一)
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- 靠QQ月入上万灰色暴利偏门的项目
- 市场何时出现转机()
- spring|spring boot项目启动websocket
- 4U