Apache cxf jaxrs服务器ServiceConstructionException

时间:2015-12-09 05:19:37

标签: java spring apache jax-rs cxf

您好我已经写了jaxrs apache cxf rest server。以前它工作正常。突然它没有启动它会给出这个错误。

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)

这是我的弹簧配置

<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>

有没有人有什么问题?

2 个答案:

答案 0 :(得分:3)

在我的情况下,它是一个cxf依赖项mismatch.cxf-spring-boot-starter-jaxrs 3.2.2与jsonProvider-rs所需的cxf-bundle-jaxrs 2.7.18不兼容。我能够通过用cxf-rt-rs-extension-providers 3.2.2替换cxf-bundle-jaxrs来解决这个问题。

答案 1 :(得分:2)

在我的情况下,我在尝试测试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();

不确定您的具体情况,但希望这至少会让您朝着正确的方向前进。