sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.97k stars 1.27k forks source link

springboot 使用webjars 启动报错 #366

Closed jackcailj closed 5 years ago

jackcailj commented 5 years ago

前端资源使用webjars 管理,启动sofaboot时,异常:看源码是读取webjars资源jar包时,报错了。是不支持webjars吗?

sofaboot版本:2.6.1

2019-03-01 15:37:08.235 | main | ERROR | org.springframework.boot.SpringApplication | SpringApplication.java(771) | Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.NullPointerException: entry
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1178)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
        at com.creditease.testplatform.TestplatformApplication.main(TestplatformApplication.java:18)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.alipay.sofa.ark.bootstrap.MainMethodRunner.run(MainMethodRunner.java:48)
        at com.alipay.sofa.ark.container.model.BizModel.start(BizModel.java:179)
        at com.alipay.sofa.ark.container.service.biz.DefaultBizDeployer.deploy(DefaultBizDeployer.java:52)
        at com.alipay.sofa.ark.container.service.biz.BizDeployServiceImpl.deploy(BizDeployServiceImpl.java:55)
        at com.alipay.sofa.ark.container.pipeline.DeployBizStage.process(DeployBizStage.java:44)
        at com.alipay.sofa.ark.container.pipeline.StandardPipeline.process(StandardPipeline.java:73)
        at com.alipay.sofa.ark.container.ArkContainer.start(ArkContainer.java:113)
        at com.alipay.sofa.ark.container.ArkContainer.main(ArkContainer.java:69)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.alipay.sofa.ark.bootstrap.MainMethodRunner.run(MainMethodRunner.java:48)
        at com.alipay.sofa.ark.bootstrap.AbstractLauncher.launch(AbstractLauncher.java:108)
        at com.alipay.sofa.ark.bootstrap.AbstractLauncher.launch(AbstractLauncher.java:52)
        at com.alipay.sofa.ark.bootstrap.ArkLauncher.main(ArkLauncher.java:35)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.NullPointerException: entry
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 37 common frames omitted
Caused by: java.lang.NullPointerException: entry
        at java.util.zip.ZipFile.getInputStream(Unknown Source)
        at java.util.jar.JarFile.getInputStream(Unknown Source)
        at org.webjars.urlprotocols.JarUrlProtocolHandler.getAssetPaths(JarUrlProtocolHandler.java:45)
        at org.webjars.WebJarAssetLocator.getAssetPaths(WebJarAssetLocator.java:91)
        at org.webjars.WebJarAssetLocator.getFullPathIndex(WebJarAssetLocator.java:121)
        at org.webjars.WebJarAssetLocator.<init>(WebJarAssetLocator.java:152)
        at org.springframework.web.servlet.resource.WebJarsResourceResolver.<init>(WebJarsResourceResolver.java:60)
        at org.springframework.web.servlet.config.annotation.ResourceChainRegistration.getResourceResolvers(ResourceChainRegistration.java:113)
        at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration.getRequestHandler(ResourceHandlerRegistration.java:161)
        at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getHandlerMapping(ResourceHandlerRegistry.java:157)
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:459)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$be4d6f81.CGLIB$resourceHandlerMapping$39(<generated>)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$be4d6f81$$FastClassBySpringCGLIB$$549bd131.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$be4d6f81.resourceHandlerMapping(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 38 common frames omitted
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.alipay.sofa.ark.bootstrap.MainMethodRunner.run(MainMethodRunner.java:48)
        at com.alipay.sofa.ark.bootstrap.AbstractLauncher.launch(AbstractLauncher.java:108)
        at com.alipay.sofa.ark.bootstrap.AbstractLauncher.launch(AbstractLauncher.java:52)
        at com.alipay.sofa.ark.bootstrap.ArkLauncher.main(ArkLauncher.java:35)
Caused by: com.alipay.sofa.ark.exception.ArkException: com.alipay.sofa.ark.exception.ArkException: java.lang.reflect.InvocationTargetException
        at com.alipay.sofa.ark.container.pipeline.StandardPipeline.process(StandardPipeline.java:79)
        at com.alipay.sofa.ark.container.ArkContainer.start(ArkContainer.java:113)
        at com.alipay.sofa.ark.container.ArkContainer.main(ArkContainer.java:69)
        ... 8 more
Caused by: com.alipay.sofa.ark.exception.ArkException: java.lang.reflect.InvocationTargetException
        at com.alipay.sofa.ark.container.service.biz.DefaultBizDeployer.deploy(DefaultBizDeployer.java:56)
        at com.alipay.sofa.ark.container.service.biz.BizDeployServiceImpl.deploy(BizDeployServiceImpl.java:55)
        at com.alipay.sofa.ark.container.pipeline.DeployBizStage.process(DeployBizStage.java:44)
        at com.alipay.sofa.ark.container.pipeline.StandardPipeline.process(StandardPipeline.java:73)
        ... 10 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.alipay.sofa.ark.bootstrap.MainMethodRunner.run(MainMethodRunner.java:48)
        at com.alipay.sofa.ark.container.model.BizModel.start(BizModel.java:179)
        at com.alipay.sofa.ark.container.service.biz.DefaultBizDeployer.deploy(DefaultBizDeployer.java:52)
        ... 13 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.NullPointerException: entry
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1178)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1072)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
        at com.creditease.testplatform.TestplatformApplication.main(TestplatformApplication.java:18)
        ... 20 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'resourceHandlerMapping' threw exception; nested exception is java.lang.NullPointerException: entry
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        ... 37 more
Caused by: java.lang.NullPointerException: entry
        at java.util.zip.ZipFile.getInputStream(Unknown Source)
        at java.util.jar.JarFile.getInputStream(Unknown Source)
        at org.webjars.urlprotocols.JarUrlProtocolHandler.getAssetPaths(JarUrlProtocolHandler.java:45)
        at org.webjars.WebJarAssetLocator.getAssetPaths(WebJarAssetLocator.java:91)
        at org.webjars.WebJarAssetLocator.getFullPathIndex(WebJarAssetLocator.java:121)
        at org.webjars.WebJarAssetLocator.<init>(WebJarAssetLocator.java:152)
        at org.springframework.web.servlet.resource.WebJarsResourceResolver.<init>(WebJarsResourceResolver.java:60)
        at org.springframework.web.servlet.config.annotation.ResourceChainRegistration.getResourceResolvers(ResourceChainRegistration.java:113)
        at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration.getRequestHandler(ResourceHandlerRegistration.java:161)
        at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getHandlerMapping(ResourceHandlerRegistry.java:157)
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:459)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$be4d6f81.CGLIB$resourceHandlerMapping$39(<generated>)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$be4d6f81$$FastClassBySpringCGLIB$$549bd131.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
        at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$be4d6f81.resourceHandlerMapping(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 38 more
QilongZhang commented 5 years ago
Caused by: java.lang.NullPointerException: entry
at java.util.zip.ZipFile.getInputStream(Unknown Source)
at java.util.jar.JarFile.getInputStream(Unknown Source)
at org.webjars.urlprotocols.JarUrlProtocolHandler.getAssetPaths(JarUrlProtocolHandler.java:45)

看下这里为什么会报NPE

jackcailj commented 5 years ago

跟踪了下源代码,webjars老版本不支持jar包中还有jar包加载资源,更换新版本,支持了。

QilongZhang commented 5 years ago

@jackcailj 好的。