Spring Boot & Apache CXF developed with multiple endpoint Webservice__webservice

Source: Internet
Author: User

By integrating the Apache CXF development WebService with spring Boot, you can avoid a large number of XML configuration files from previous spring. There are many public examples of developing webservice in this way, for example:

Detailed Spring BOOT+CXF Development WebService Demo

Spring Boot & Apache cxf--simple WebService and user authentication

Spring Boot Consolidation CXF Development Web Service

Spring Boot Consolidation CXF Publishing WebService services and CXF client calls

Spring Boot & Apache cxf–how to SOAP in 2016

These use cases are simple and intuitive, can quickly realize a single Endpint WebService server, this article no longer repeat. But in reality, it is often in a Web service with many types of business endpoints, even the same business but different versions of the endpoints. How it should be done at this time.

In fact, as long as the CXF configuration file continues to add endpoint and the corresponding WebService implementation. The following is the instance code that is currently validated.

@Configuration public class Cxfconfig {@Bean public Servletregistrationbean Dispatcherservlet () {return
    New Servletregistrationbean (New Cxfservlet (), "/services/*");
    @Bean (name = bus.default_bus_id) public Springbus Springbus () {return new Springbus ();
    @Bean public MyService MyService () {return new Myserviceimpl ();
        @Bean public Endpoint Endpoint () {Endpointimpl Endpoint = new Endpointimpl (Springbus (), MyService ());
        Endpoint.publish ("/myservice");
    return endpoint;
     }/** * Another Webservice of Mine.
    * @return * * @Bean public anotherservice Anotherservice () {return new Anotherserviceimpl (); @Bean public Endpointimpl anotherendpoint (Anotherservice anotherservice) {Endpointimpl endpoint = new
        Endpointimpl (Springbus (), anotherservice);
        Endpoint.publish ("/another");
    return endpoint; }
}

If you want multiple versions of endpoint to exist, you can do so by creating different versions of the Cxfconfig class. Each Cxfconfig class contains a springbus and Servletregistrationbean.

For example, for the following two versions of the API:

/api/v1/orders/get
/api/v1/orders/create
/api/v2/orders/get
/api/v2/orders/create

The following two configuration classes can be defined by Springboot:
Someapiv1config class:

 @Configuration public class Someapiv1config {@Bean public springbus springBusV1 () {
        Springbus bus = new Springbus ();
        Bus.setid ("v1");
    return bus;
        @Bean public Servletregistrationbean V1servlet () {Cxfservlet cxfservlet = new Cxfservlet ();

        Cxfservlet.setbus (SpringBusV1 ());
        Servletregistrationbean Servletbean = new Servletregistrationbean (Cxfservlet, "/api/v1/*");
        Servletbean.setname ("v1");
    return Servletbean; @Bean public Endpointimpl getOrderV1 (GetOrderServiceV1 service) {Endpointimpl endpoint = new Endpointi
        MPL (springBusV1 (), service);
        Endpoint.publish ("/orders/get");
    return endpoint; @Bean public Endpointimpl createOrderV1 (CreateOrderServiceV1 service) {Endpointimpl endpoint = new End
        Pointimpl (springBusV1 (), service);
        Endpoint.publish ("/orders/create");
    return endpoint; }
}

Someapiv2config class:

 @Configuration public class Someapiv2config {@Bean public springbus springBusV2 () {
        Springbus bus = new Springbus ();
        Bus.setid ("v2");
    return bus;
        @Bean public Servletregistrationbean V2servlet () {Cxfservlet cxfservlet = new Cxfservlet ();

        Cxfservlet.setbus (SpringBusV2 ());
        Servletregistrationbean Servletbean = new Servletregistrationbean (Cxfservlet, "/api/v2/*");
        Servletbean.setname ("v2");
    return Servletbean; @Bean public Endpointimpl getOrderV2 (GetOrderServiceV2 service) {Endpointimpl endpoint = new Endpointi
        MPL (springBusV2 (), service);
        Endpoint.publish ("/orders/get");
    return endpoint; @Bean public Endpointimpl createOrderV2 (CreateOrderServiceV2 service) {Endpointimpl endpoint = new End
        Pointimpl (springBusV2 (), service);
        Endpoint.publish ("/orders/create");
    return endpoint; }

}

The

example above is derived from the multiple endpoints using CXF and Spring Boot.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.