OSG框架下使用JAXB出现ClassCastException

以下是实现代码:

JAXBContext jc = JAXBContext.newInstance("cn.capitek.stat.fuse.predeal.config.ftp");
Unmarshaller u = jc.createUnmarshaller();
InputStream in = CCommonFunc.getInputStream("META-INF/conf-test/ftp.xml");
JAXBElement<?> reportconfigElement = (JAXBElement<?>)u.unmarshal(in);
in.close();

//测试对象类型
Object obj = reportconfigElement.getValue();
System.out.println(obj.getClass());
System.out.println(obj.equals(new FtpConfigType()));

List<FtpType> ftpArray=((FtpConfigType)reportconfigElement.getValue()).getFtp();
System.out.println("============="+ftpArray.size());


使用spring osgi test进行单元测试

[quote]
java.lang.ClassCastException: cn.capitek.stat.fuse.predeal.config.ftp.FtpConfigType
at cn.capitek.stat.fuse.predeal.service.collector.impl.FtpFileCollectorsManager.getFtpList(FtpFileCollectorsManager.java:156)
at cn.capitek.stat.fuse.predeal.service.collector.impl.FtpFileCollectorsManager.startCollectors(FtpFileCollectorsManager.java:95)
at test.cn.capitek.stat.fuse.predeal.service.collector.impl.TestFtpFileCollectorsManager.testGetFile(TestFtpFileCollectorsManager.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at org.springframework.osgi.test.AbstractOsgiTests.osgiRunTest(AbstractOsgiTests.java:553)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:193)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:178)
at org.springframework.osgi.test.internal.support.OsgiJUnitTestAdapter.osgiRunTest(OsgiJUnitTestAdapter.java:76)
at org.springframework.osgi.test.internal.support.OsgiJUnitService$1.protect(OsgiJUnitService.java:101)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at org.springframework.osgi.test.internal.support.OsgiJUnitService.runTest(OsgiJUnitService.java:98)
at org.springframework.osgi.test.internal.support.OsgiJUnitService.executeTest(OsgiJUnitService.java:71)
at org.springframework.osgi.test.internal.support.OsgiJUnitService.runTest(OsgiJUnitService.java:45)
at org.springframework.osgi.test.JUnitTestActivator.executeTest(JUnitTestActivator.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.osgi.test.AbstractOsgiTests.invokeOSGiTestExecution(AbstractOsgiTests.java:397)
at org.springframework.osgi.test.AbstractOsgiTests.runBare(AbstractOsgiTests.java:206)
at org.springframework.osgi.test.AbstractOsgiTests$1.protect(AbstractOsgiTests.java:184)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at org.springframework.osgi.test.AbstractOsgiTests.run(AbstractOsgiTests.java:181)
at junit.framework.TestSuite.runTest(TestSuite.java:230)
at junit.framework.TestSuite.run(TestSuite.java:225)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

[/quote]


直接junit测试该段代码没有问题,个人猜测又是可恶的classloader导致的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值