2023-07-03T14:33:26.923+08:00 WARN 20580 --- [ main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSocketHandlerMapping': Unsatisfied dependency expressed through method 'webSocketHandlerMapping' parameter 0: Error creating bean with name 'defaultSockJsSchedulerContainer': Instantiation of supplied bean failed
2023-07-03T14:33:26.924+08:00 INFO 20580 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2023-07-03T14:33:26.924+08:00 ERROR 20580 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSocketHandlerMapping': Unsatisfied dependency expressed through method 'webSocketHandlerMapping' parameter 0: Error creating bean with name 'defaultSockJsSchedulerContainer': Instantiation of supplied bean failed
at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:315) ~[na:na]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArguments(BeanInstanceSupplier.java:258) ~[na:na]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:198) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1214) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[boot-test.exe:6.0.9]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941) ~[boot-test.exe:6.0.9]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[boot-test.exe:6.0.9]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[boot-test.exe:3.1.1]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[boot-test.exe:3.1.1]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:436) ~[boot-test.exe:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[boot-test.exe:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[boot-test.exe:3.1.1]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[boot-test.exe:3.1.1]
at com.benfei.ChangAnRefuelApplication.main(ChangAnRefuelApplication.java:11) ~[boot-test.exe:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultSockJsSchedulerContainer': Instantiation of supplied bean failed
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1220) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1417) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:888) ~[na:na]
at org.springframework.beans.factory.support.RegisteredBean.resolveAutowiredArgument(RegisteredBean.java:219) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:312) ~[na:na]
... 21 common frames omitted
Caused by: java.lang.IllegalArgumentException: WebSocketHandler must not be null
at org.springframework.util.Assert.notNull(Assert.java:204) ~[na:na]
at org.springframework.web.socket.config.annotation.AbstractWebSocketHandlerRegistration.addHandler(AbstractWebSocketHandlerRegistration.java:65) ~[boot-test.exe:6.0.9]
at org.springframework.web.socket.config.annotation.ServletWebSocketHandlerRegistry.addHandler(ServletWebSocketHandlerRegistry.java:59) ~[na:na]
at com.benfei.web.socket.WebSocketConfig.registerWebSocketHandlers(WebSocketConfig.java:19) ~[boot-test.exe:na]
at org.springframework.web.socket.config.annotation.DelegatingWebSocketConfiguration.registerWebSocketHandlers(DelegatingWebSocketConfiguration.java:52) ~[boot-test.exe:6.0.9]
at org.springframework.web.socket.config.annotation.WebSocketConfigurationSupport.initHandlerRegistry(WebSocketConfigurationSupport.java:58) ~[boot-test.exe:6.0.9]
at org.springframework.web.socket.config.annotation.WebSocketConfigurationSupport.defaultSockJsSchedulerContainer(WebSocketConfigurationSupport.java:87) ~[boot-test.exe:6.0.9]
at org.springframework.web.socket.config.annotation.WebSocketConfigurationSupport__BeanDefinitions.lambda$getDefaultSockJsSchedulerContainerInstanceSupplier$1(WebSocketConfigurationSupport__BeanDefinitions.java:37) ~[na:na]
at org.springframework.util.function.ThrowingFunction.apply(ThrowingFunction.java:63) ~[boot-test.exe:6.0.9]
at org.springframework.util.function.ThrowingFunction.apply(ThrowingFunction.java:51) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.lambda$withGenerator$0(BeanInstanceSupplier.java:167) ~[na:na]
at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:68) ~[boot-test.exe:6.0.9]
at org.springframework.util.function.ThrowingBiFunction.apply(ThrowingBiFunction.java:54) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.lambda$get$2(BeanInstanceSupplier.java:200) ~[na:na]
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58) ~[boot-test.exe:6.0.9]
at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.invokeBeanSupplier(BeanInstanceSupplier.java:212) ~[na:na]
at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:200) ~[na:na]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[boot-test.exe:6.0.9]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1214) ~[boot-test.exe:6.0.9]
... 34 common frames omitted
Comment From: wilkinsona
Thanks for the report. Unfortunately, a stack trace alone isn't enough to diagnose the problem. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.
Comment From: okboyone
test.zip Thank you very much. Our team has been experimenting extensively with the combination of springboot 3+graalvm in the industrial field for several months now
Comment From: okboyone
test.zip Thank you very much. Our team has been experimenting extensively with the combination of springboot 3+graalvm in the industrial field for several months now
I used the build method provided in the official documentation and used the mvn -Pnative native:compile command to build it
Comment From: wilkinsona
Thanks for the sample, @okboyone. I've reproduced the problem. It also occurs on the JVM when the app has undergone AOT processing. You can work around it by using @Autowired
instead of @Resource
to inject MyWsHandler
into WebSocketConfig
. I'll transfer this issue to the Spring Framework team as they may want to investigate why @Resource
does not work.
Generally speaking, we don't recommend the use of field injection so you may want to update WebSocketConfig
to use constructor injection irrespective of any problems related to AOT.
Comment From: sdeleuze
Looks like a duplicate of #29614 as far as I can tell.
Comment From: snicoll
Duplicates #29614