gpt4 book ai didi

java - CXF.jaxrs : IllegalArgumentException when using JAXRSServerFactoryBean

转载 作者:太空宇宙 更新时间:2023-11-04 08:57:57 27 4
gpt4 key购买 nike

在单元测试中设置 JAXRS 测试服务时,我遇到了以下问题。这是代码(取自 AbstractJUnit4SpringContextTests 派生的测试类):

    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setServiceBeans(applicationContext.getBean("searchXY"));
sf.setAddress("http://localhost:9000/");
sf.create();

restClient = new RestTestClient();//custom class for client-side testing

....

InputStream dummyRequestFileAsStream = getInputStreamForClasspathResource(
DUMMY_REQUEST_FILE);
LOGGER.info("Testing searchQuery ReST service access");
int httpStatus = restClient.postXmlStream(
"http://localhost:9000/search/searchXY",
dummyRequestFileAsStream);

我正在将 XML 测试文件输入到服务中。 CXF 会不恰本地尝试将 xml 包装到 javax.xml.bind.JAXBElement 中,调用服务,并因 IllegalArgumentException(在反射 API 中)而失败,因为该服务当然不接受特定于 JAX-RS 的元素,而是接受我之前在 XSD 中定义的 SearchRequest 元素。

但是,当我将以下行插入到我的 spring 上下文中时,一切都很好:

<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />

还有人看过这个吗?

最佳答案

如果不提供更多详细信息,很难理解为什么会发生最初的问题。上面的导入始终是必需的,并且我从未尝试过在没有 Spring 上下文的情况下进行测试。异常跟踪是什么?也许如果没有导入,JAXRS 拦截器甚至不会参与?

干杯,谢尔盖

关于java - CXF.jaxrs : IllegalArgumentException when using JAXRSServerFactoryBean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1715692/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com