xrs服务器ServiceConstructionExcepti

xrs服务器ServiceConstructionExcepti

本文介绍了Apache CXF Jaxrs服务器ServiceConstructionException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了jaxrs apache cxf rest服务器.以前它可以正常工作.突然它没有启动,并且出现此错误.

Hi i have write jaxrs apache cxf rest server .previously it works fine.suddenly it didn't start and it gives this error.

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>

有没有人是什么问题?

推荐答案

就我而言,在尝试测试CXF JAX_RX API时遇到了这个问题.在尝试在测试情况下创建服务器时遇到了这个问题.我尝试了几种不同的方法...

In my case I was running into this problem while trying to test a CXF JAX_RX API. I was running into this problem while trying to create a server in a test situation. I tried a few different approaches...

这是我的ClassCastException游戏:

This game me the 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();

最终使我能够解决该异常的原因是:

What ended up working for me to get around that exception was this:

JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
sf.setAddress("api/address");
server = serverFactory.create();
server.start();

不确定您的具体情况,但希望这至少可以使您朝正确的方向前进.

Not sure of your specific situation but hopefully this at least gets you going in the right direction.

这篇关于Apache CXF Jaxrs服务器ServiceConstructionException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 19:59