下面的代码在Oracle Java 7 和 8上运行得非常好,但在 OpenJDK 上却失败了(我试过https://adoptopenjdk.net/和 RedHat's )。
ApplicationContext appContext = new ClassPathXmlApplicationContext("EdtAppContext.xml");
this.mainView = appContext.getBean(EdtMainView.class);
当我配置 openJDK 时,我遇到了异常
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.globaltools.edt.bootstrap.EdtStartUp.main(EdtStartUp.java:34)
at com.globaltools.flexpay.main.gui.FlexPayApp.main(FlexPayApp.java:17)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'EdtMainView' defined in class path resource [EdtAppContext.xml]: Cannot resolve reference to bean 'FlexPayApp' while setting bean property 'applications' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FlexPayApp' defined in class path resource [EdtAppContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.globaltools.flexpay.main.gui.FlexPayView]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedSet(BeanDefinitionValueResolver.java:370)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1305)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.globaltools.edt.bootstrap.EdtContext.<init>(EdtContext.java:45)
at com.globaltools.edt.bootstrap.EdtContext.<clinit>(EdtContext.java:12)
... 2 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'FlexPayApp' defined in class path resource [EdtAppContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.globaltools.flexpay.main.gui.FlexPayView]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:890)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 20 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.globaltools.flexpay.main.gui.FlexPayView]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:938)
... 28 more
Caused by: java.lang.ExceptionInInitializerError
at com.globaltools.flexpay.model.FlexPayContext.<clinit>(FlexPayContext.java:55)
at com.globaltools.flexpay.main.gui.FlexPayController.initController(FlexPayController.java:86)
at com.globaltools.edt.gui.app.EdtAppController.<init>(EdtAppController.java:41)
at com.globaltools.flexpay.main.gui.FlexPayController.<init>(FlexPayController.java:73)
at com.globaltools.flexpay.main.gui.FlexPayView.createController(FlexPayView.java:218)
at com.globaltools.flexpay.main.gui.FlexPayView.createController(FlexPayView.java:60)
at com.globaltools.edt.gui.app.EdtAppView.<init>(EdtAppView.java:55)
at com.globaltools.flexpay.main.gui.FlexPayView.<init>(FlexPayView.java:124)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
... 30 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'SpotProvider' defined in class path resource [SpotProtocolService.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'protocolDefinition' threw exception; nested exception is com.thoughtworks.xstream.converters.ConversionException: Cannot construct com.globaltools.mgp.domain.Protocol as it does not have a no-args constructor : Cannot construct com.globaltools.mgp.domain.Protocol as it does not have a no-args constructor
---- Debugging information ----
message : Cannot construct com.globaltools.mgp.domain.Protocol as it does not have a no-args constructor
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct com.globaltools.mgp.domain.Protocol as it does not have a no-args constructor
class : com.globaltools.mgp.domain.Protocol
required-type : com.globaltools.mgp.domain.Protocol
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /com.globaltools.mgp.domain.Protocol
line number : 2
version : null
-------------------------------
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.globaltools.edt.bootstrap.EdtServiceContext.<init>(EdtServiceContext.java:39)
at com.globaltools.edt.bootstrap.EdtServiceContext.<clinit>(EdtServiceContext.java:13)
... 43 more
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'protocolDefinition' threw exception; nested exception is com.thoughtworks.xstream.converters.ConversionException: Cannot construct com.globaltools.mgp.domain.Protocol as it does not have a no-args constructor : Cannot construct com.globaltools.mgp.domain.Protocol as it does not have a no-args constructor
---- Debugging information ----
message : Cannot construct com.globaltools.mgp.domain.Protocol as
it does not have a no-args constructor
cause-exception :
com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct com.globaltools.mgp.domain.Protocol as
it does not have a no-args constructor
class : com.globaltools.mgp.domain.Protocol
required-type : com.globaltools.mgp.domain.Protocol
converter-type :
com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /com.globaltools.mgp.domain.Protocol
line number : 2
version : null
-------------------------------
at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1338)
... 57 more
引用的XML如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<description>
Applications to be started
</description>
<bean id="EdtMainView" class="com.globaltools.edt.gui.EdtMainView">
<property name="applications">
<set>
<ref bean="FlexPayApp"/>
</set>
</property>
<property name="lookAndFeel" value ="swing.crossplatformlaf"></property>
</bean>
<bean id="FlexPayApp" class="com.globaltools.flexpay.main.gui.FlexPayView"></bean>
</beans>
没有把握
- 我是否必须找到不同的 API 来获取 XML 上下文
- 是否在 OpenJDK XML 上下文中以不同方式处理
任何帮助在这里表示赞赏。