问题描述
如题.springMVC+CXF3.0,部署到tomcat下启动,一切ok.用脚本启动一直报错NoClassDefFoundError:Couldnotinitializeclasscom.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.网上查说是jdk版本的问题,但我的已经是1.6.24,应该不存在说的问题.看了一下,报错的这个类在jdk的rt.jar和jaxb-impl-2.2.7.jar下面都有.怀疑是类加载顺序问题,在jre的endorsed下放了jaxb-impl-2.2.7.jar也是没用.请教大家,这个可能是什么问题导致.启动脚本代码:publicclassSpringUtilTest{publicstaticApplicationContextapplicationContext=newClassPathXmlApplicationContext("classpath:spring*.xml");publicstaticApplicationContextgetApplicationContext(){returnapplicationContext;}publicstaticvoidmain(String[]args){System.out.println("springinitfinlished...");System.out.println(System.getProperty("java.endorsed.dirs"));System.out.println(System.getProperty("java.ext.dirs"));AccessCANcan=(AccessCAN)getApplicationContext().getBean("accessCAN");//BaseDaodao=(BaseDao)getApplicationContext().getBean("baseDao");////TransactionDaotdao=(TransactionDao)getApplicationContext().getBean("transactionDao");try{//System.out.println(JSON.toJSONString(dao.queryForList("selectinvnoasinvNofromBTAS_Transactionwhere1=1")));//System.out.println(JSON.toJSONString(tdao.getInvnosByTimestamp("","")));//can.orderupload(null);}catch(Exceptione){e.printStackTrace();}System.out.println("over");}}
CXF配置主要就是这句:<jaxws:endpointid="IurPoServices"implementor="jeecg.citsamex.hoteliur.ws.impl.IurPoServicesImpl"address="/IurPoServices"/>
报的错误:java.lang.ExceptionInInitializerErrorCausedby:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'IurPoServices':Invocationofinitmethodfailed;nestedexceptionisjava.lang.NoClassDefFoundError:Couldnotinitializeclasscom.sun.xml.bind.v2.model.impl.RuntimeModelBuilderatorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)atorg.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)atorg.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)atorg.jeecgframework.core.util.SpringUtilTest.<clinit>(SpringUtilTest.java:17)Causedby:java.lang.NoClassDefFoundError:Couldnotinitializeclasscom.sun.xml.bind.v2.model.impl.RuntimeModelBuilderatcom.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:455)atcom.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303)atcom.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:142)atcom.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174)atcom.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:162)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atjavax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210)atjavax.xml.bind.ContextFinder.find(ContextFinder.java:368)atjavax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)atorg.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:347)atorg.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:345)atjava.security.AccessController.doPrivileged(NativeMethod)atorg.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:345)atorg.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:246)atorg.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:470)atorg.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:325)atorg.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)atorg.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:467)atorg.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:704)atorg.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:527)atorg.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261)atorg.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)atorg.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)atorg.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)atorg.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)atorg.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)atorg.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)atorg.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251)atorg.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)atjava.lang.reflect.Method.invoke(Method.java:597)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)atorg.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)...12more
解决方案
解决方案二:
看上去还是版本问题,看看是不是第三方包里有了那个包,却没那个类
解决方案三:
java.lang.NoClassDefFoundError这个异常代表着jar包不存在或者冲突
解决方案四:
引用1楼defonds的回复:
看上去还是版本问题,看看是不是第三方包里有了那个包,却没那个类
第三方就只有tomcat了,我看了tomcat下的jar包,没有哪个包里有这个类的,工程引用的就前边提到的两个jar包里有这个类.
解决方案五:
引用2楼suciver的回复:
java.lang.NoClassDefFoundError这个异常代表着jar包不存在或者冲突
jar包肯定是存在的,因为部署到tomcat下是可以启动的.现在看就是有两个jar包都有这个类,所以猜测是引用错了,但这两个jar包感觉都不能删里面的类的,有什么方式可以设置先加载哪个类吗,我试着在jre下的设置好像是没有作用的.