在基于Spring Boot的应用程序中启动多个WAR时,通常会遇到以下异常情况:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.foo.SomeService]: Factory method 'someService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someBean' defined in com.foo.SomeJavaConfig: Post-processing of merged bean definition failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1181)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1075)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
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.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at com.ibm.ws.webcontainer.webapp.WebApp.initializeServletContainerInitializers(WebApp.java:2487)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:994)
at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6566)
...
Caused by: java.lang.NullPointerException: null
at com.ibm.ws.classloading.internal.AppClassLoader.getClassSpecificProtectionDomainPrivileged(AppClassLoader.java:367)
at com.ibm.ws.classloading.internal.AppClassLoader.access$000(AppClassLoader.java:64)
at com.ibm.ws.classloading.internal.AppClassLoader$2.run(AppClassLoader.java:351)
at com.ibm.ws.classloading.internal.AppClassLoader$2.run(AppClassLoader.java:348)
at java.security.AccessController.doPrivileged(Native Method)
at com.ibm.ws.classloading.internal.AppClassLoader.getClassSpecificProtectionDomain(AppClassLoader.java:348)
at com.ibm.ws.classloading.internal.AppClassLoader.definePackageAndClass(AppClassLoader.java:325)
at com.ibm.ws.classloading.internal.AppClassLoader.findClass(AppClassLoader.java:271)
at com.ibm.ws.classloading.internal.ParentLastClassLoader.findOrDelegateLoadClass(ParentLastClassLoader.java:80)
at com.ibm.ws.classloading.internal.AppClassLoader.loadClass(AppClassLoader.java:443)
at com.ibm.ws.classloading.internal.ParentLastClassLoader.loadClass(ParentLastClassLoader.java:50)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:489)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:431)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:397)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:333)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1000)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:523)
... 76 common frames omitted
这不是确定性的-碰巧所有WAR都进展顺利。
在WLP版本18.0.0.3和19.0.0.3(未在其他版本上进行测试)上可以复制该问题。
春季版本4.3.17.RELEASE
对我来说,这似乎是一个错误,但也许有人已经对此进行了修复,可以为您提供帮助。
答案 0 :(得分:0)
您使用什么Java级别来运行此方案?这个问题可能与Java有关,而不与Liberty有关,这就是我要问的原因。我们已经在某些Java级别中看到了非确定性NullPointerExceptions的一些问题,这些问题已在后来的Java级别中修复。
AppClassLoader从18.0.0.3到19.0.0.3进行了很多更改,但是您提供的堆栈来自18.0.0.3级别的代码,该代码已经很长时间没有改变了,因此看起来不是一个新问题。如果是Liberty问题,则在OpenLiberty github上打开一个问题将是适当的。您可能需要通过跟踪来重现该问题,以便IBM对其进行更多调试。我建议使用的跟踪规范是com.ibm.ws.classloading。* = finest:com.ibm.ws.artifact。* = finest