質問

Is there an built in HTTP server in Apache CXF like "HttpServerFactory" of Jersey? I tried reading through the CXF documentation but couldn't find anything similar.

役に立ちましたか?

解決

Yes, there is.

If you want JAX-RS service deployed on built-in server use org.apache.cxf.jaxrs.JAXRSServerFactoryBean. Example usage (taken from CXF samples):

JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(CustomerService.class);
sf.setResourceProvider(CustomerService.class, 
    new SingletonResourceProvider(new CustomerService()));
sf.setAddress("http://localhost:9000/");

sf.create();

If you want JAX-WS service deployed on built-in server you can use javax.xml.ws.Endpoint.publish(..). Sample code (again copied from CXF Sample):

    HelloWorldImpl implementor = new HelloWorldImpl();
    String address = "http://localhost:9000/helloWorld";
    Endpoint.publish(address, implementor);

Both JAX-WS and JAX-RS require adding org.apache.cxf:cxf-rt-transports-http-jetty to classpath.

I really recommend taking look at CXF samples. Sometimes they are indispensable.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top