提问人:Roy_96 提问时间:10/31/2023 更新时间:10/31/2023 访问量:87
Native-Image/Spring Boot:BeanCreationException:创建名为“resourceHandlerMapping”的 Bean 时出错:提供的 Bean 的实例化失败
Native-Image/Spring Boot: BeanCreationException: Error creating bean with name 'resourceHandlerMapping': Instantiation of supplied bean failed
问:
我一直在尝试使用 GraalVM-native-image 制作 RESTful 后端的独立原生。因此,我使用了 graal 的内置代理来设置所有必要的 *-config.json 文件。当我使用 ./gradlew 运行后端项目或运行 jar 时,一切都运行得无所适从。但是,在 ./gradlew nativeCompile 方法之后,native-image 不起作用。我收到以下异常堆栈跟踪,我不知道如何修复它。似乎接口 ModuleReader 有问题,它在reflect-config.json中有一个反射。它的 list() 方法抛出一个 IllegalArgument 异常。但我真的不知道,如何解决这个问题。
堆栈跟踪:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceHandlerMapping': Instantiation of supplied bean failed
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1220) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[soa-app:6.0.8]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:917) ~[soa-app:6.0.8]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[soa-app:6.0.8]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[soa-app:3.0.6]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[soa-app:3.0.6]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[soa-app:3.0.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[soa-app:3.0.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[soa-app:3.0.6]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[soa-app:3.0.6]
at at.ntbs.soa.App.main(App.java:10) ~[soa-app:na]
Caused by: io.github.classgraph.ClassGraphException: Uncaught exception during scan
at io.github.classgraph.ClassGraph.scan(ClassGraph.java:1606) ~[na:na]
at io.github.classgraph.ClassGraph.scan(ClassGraph.java:1623) ~[na:na]
at io.github.classgraph.ClassGraph.scan(ClassGraph.java:1636) ~[na:na]
at org.webjars.WebJarAssetLocator.scanForWebJars(WebJarAssetLocator.java:188) ~[soa-app:na]
at org.webjars.WebJarAssetLocator.<init>(WebJarAssetLocator.java:210) ~[soa-app:na]
at org.webjars.WebJarAssetLocator.<init>(WebJarAssetLocator.java:194) ~[soa-app:na]
at org.springframework.web.servlet.resource.WebJarsResourceResolver.<init>(WebJarsResourceResolver.java:63) ~[na:na]
at org.springframework.web.servlet.config.annotation.ResourceChainRegistration.getResourceResolvers(ResourceChainRegistration.java:114) ~[soa-app:6.0.8]
at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration.getRequestHandler(ResourceHandlerRegistration.java:215) ~[soa-app:6.0.8]
at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getRequestHandler(ResourceHandlerRegistry.java:178) ~[soa-app:6.0.8]
at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getHandlerMapping(ResourceHandlerRegistry.java:168) ~[soa-app:6.0.8]
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:589) ~[soa-app:6.0.8]
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport__BeanDefinitions.lambda$getResourceHandlerMappingInstanceSupplier$7(WebMvcConfigurationSupport__BeanDefinitions.java:166) ~[na:na]
at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:68) ~[soa-app:6.0.8]
at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:54) ~[soa-app:6.0.8]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.lambda$get$2(BeanInstanceSupplier.java:204) ~[na:na]
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58) ~[soa-app:6.0.8]
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46) ~[soa-app:6.0.8]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.invokeBeanSupplier(BeanInstanceSupplier.java:216) ~[na:na]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:204) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[soa-app:6.0.8]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1214) ~[soa-app:6.0.8]
... 17 common frames omitted
Caused by: java.lang.IllegalArgumentException: Method "list" could not be invoked: java.lang.reflect.InvocationTargetException
at nonapi.io.github.classgraph.reflection.ReflectionUtils.invokeMethod(ReflectionUtils.java:231) ~[na:na]
at io.github.classgraph.ModuleReaderProxy.list(ModuleReaderProxy.java:108) ~[soa-app:4.8.147]
at io.github.classgraph.ClasspathElementModule.scanPaths(ClasspathElementModule.java:304) ~[na:na]
at io.github.classgraph.Scanner$4.processWorkUnit(Scanner.java:1091) ~[na:na]
at io.github.classgraph.Scanner$4.processWorkUnit(Scanner.java:1085) ~[na:na]
at nonapi.io.github.classgraph.concurrency.WorkQueue.runWorkLoop(WorkQueue.java:246) ~[soa-app:4.8.147]
at nonapi.io.github.classgraph.concurrency.WorkQueue.access$000(WorkQueue.java:50) ~[soa-app:4.8.147]
at nonapi.io.github.classgraph.concurrency.WorkQueue$1.call(WorkQueue.java:201) ~[na:na]
at nonapi.io.github.classgraph.concurrency.WorkQueue$1.call(WorkQueue.java:198) ~[na:na]
at java.bas[email protected]/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[soa-app:na]
at [email protected]/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[soa-app:na]
at [email protected]/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
at [email protected]/java.lang.Thread.run(Thread.java:833) ~[soa-app:na]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:838) ~[soa-app:na]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:211) ~[na:na]
反射:
{
"name":"java.lang.module.ModuleReader",
"queryAllDeclaredMethods":true,
"methods":[{"name":"list","parameterTypes":[] }]
}
我试图省略上述反射,但后来出现了问题,因为它丢失了。
答:
0赞
Roy_96
10/31/2023
#1
好的,我解决了我的问题。我仍然不知道为什么会这样,但我现在很高兴,我想:
因此,我删除了reflect-config.json文件中的以下反射:
{
"name":"jdk.internal.loader.BuiltinClassLoader",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"jdk.internal.loader.ClassLoaders$AppClassLoader",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
},
{
"name":"jdk.internal.loader.ClassLoaders$PlatformClassLoader",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true
}
{
"name":"java.lang.module.ModuleReader",
"queryAllDeclaredMethods":true,
"methods":[{"name":"list","parameterTypes":[] }]
},
{
"name":"java.lang.module.ModuleReference",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"methods":[{"name":"descriptor","parameterTypes":[] }, {"name":"location","parameterTypes":[] }, {"name":"open","parameterTypes":[] }]
}
评论