Apache cxf jaxrs 服务器 ServiceConstructionException
Apache cxf jaxrs server ServiceConstructionException
你好,我写了 jaxrs apache cxf rest server 。以前它工作 fine.suddenly 它没有启动,它给出了这个错误。
Caused by: java.lang.ClassCastException: org.apache.cxf.jaxrs.model.wadl.WadlGenerator cannot be cast to javax.ws.rs.container.ContainerRequestFilter
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.createWadlGenerator(ServerProviderFactory.java:104)
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.<init>(ServerProviderFactory.java:95)
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.initBaseFactory(ServerProviderFactory.java:132)
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.createInstance(ServerProviderFactory.java:116)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.setupFactory(JAXRSServerFactoryBean.java:234)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:182)
这是我的 spring 配置
<jaxrs:server name="server" address="${url}">
<jaxrs:serviceBeans>
<ref bean="serverApi"/>
<ref bean="swaggerResourceJSON"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jacksonProvider"/>
<ref bean="resourceWriter"/>
<ref bean="apiWriter"/>
<ref bean="corsFilter"/>
</jaxrs:providers>
</jaxrs:server>
有没有人有什么问题??
就我而言,我在尝试测试 CXF JAX_RX API 时 运行 遇到了这个问题。在尝试在测试情况下创建服务器时,我 运行 遇到了这个问题。我尝试了几种不同的方法...
这个游戏我遇到了 ClassCastException:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
sf.setAddress("api/address");
sf.setResourceClasses(OurJaxResource.class);
server = sf.create();
这样做:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(OurJaxResource.class);
List<Object> providers = new ArrayList<Object>();
sf.setProviders(providers);
sf.setResourceProvider(OurJaxResource.class, new SingletonResourceProvider(new OurJaxResource(), true));
sf.setAddress(ENDPOINT_ADDRESS);
server = sf.create();
最终让我绕过这个异常的是:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
sf.setAddress("api/address");
server = serverFactory.create();
server.start();
不确定您的具体情况,但希望这至少能让您朝着正确的方向前进。
在我的例子中,这是 cxf 依赖项不匹配。cxf-spring-boot-starter-jaxrs 3.2.2 与 jsonProvider-rs 所需的 cxf-bundle-jaxrs 2.7.18 不兼容。我能够通过将 cxf-bundle-jaxrs 替换为 cxf-rt-rs-extension-providers 3.2.2
来解决问题
你好,我写了 jaxrs apache cxf rest server 。以前它工作 fine.suddenly 它没有启动,它给出了这个错误。
Caused by: java.lang.ClassCastException: org.apache.cxf.jaxrs.model.wadl.WadlGenerator cannot be cast to javax.ws.rs.container.ContainerRequestFilter
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.createWadlGenerator(ServerProviderFactory.java:104)
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.<init>(ServerProviderFactory.java:95)
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.initBaseFactory(ServerProviderFactory.java:132)
at org.apache.cxf.jaxrs.provider.ServerProviderFactory.createInstance(ServerProviderFactory.java:116)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.setupFactory(JAXRSServerFactoryBean.java:234)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:182)
这是我的 spring 配置
<jaxrs:server name="server" address="${url}">
<jaxrs:serviceBeans>
<ref bean="serverApi"/>
<ref bean="swaggerResourceJSON"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jacksonProvider"/>
<ref bean="resourceWriter"/>
<ref bean="apiWriter"/>
<ref bean="corsFilter"/>
</jaxrs:providers>
</jaxrs:server>
有没有人有什么问题??
就我而言,我在尝试测试 CXF JAX_RX API 时 运行 遇到了这个问题。在尝试在测试情况下创建服务器时,我 运行 遇到了这个问题。我尝试了几种不同的方法...
这个游戏我遇到了 ClassCastException:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
sf.setAddress("api/address");
sf.setResourceClasses(OurJaxResource.class);
server = sf.create();
这样做:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(OurJaxResource.class);
List<Object> providers = new ArrayList<Object>();
sf.setProviders(providers);
sf.setResourceProvider(OurJaxResource.class, new SingletonResourceProvider(new OurJaxResource(), true));
sf.setAddress(ENDPOINT_ADDRESS);
server = sf.create();
最终让我绕过这个异常的是:
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
sf.setAddress("api/address");
server = serverFactory.create();
server.start();
不确定您的具体情况,但希望这至少能让您朝着正确的方向前进。
在我的例子中,这是 cxf 依赖项不匹配。cxf-spring-boot-starter-jaxrs 3.2.2 与 jsonProvider-rs 所需的 cxf-bundle-jaxrs 2.7.18 不兼容。我能够通过将 cxf-bundle-jaxrs 替换为 cxf-rt-rs-extension-providers 3.2.2
来解决问题