Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleJAX-RS Configuration
package sample.rs.service;
import java.util.Arrays;

import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import sample.rs.service.hello1.HelloServiceImpl1;
import sample.rs.service.hello2.HelloServiceImpl2;

@SpringBootApplication
public class SampleRestApplication {
    @Autowired
    private Bus bus;

    public static void main(String[] args) {
        SpringApplication.run(SampleRestApplication.class, args);
    }
 
    @Bean
    public Server rsServer() {
        JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
        endpoint.setBus(bus);
        endpoint.setAddress("/");
        // Register 2 JAX-RS root resources supporting "/sayHello/{id}" and "/sayHello2/{id}" relative paths
        endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl1(), new HelloServiceImpl2()));
        endpoint.setAddress("/");
        endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
        return endpoint.create();
    }
}

...

"http://localhost:8080/services/sayHisayHello/ApacheCxfUser". The above code also makes Swagger docs available at "http://localhost:8080/services/swagger.json".

...

For example, given the following application.yml properties:

Code Block
languagetext
titleApplication Properties
 cxf:
  jaxrs:
    component-scan: true
    classes-scan-packages: org.apache.cxf.jaxrs.swagger

...

Code Block
languagejava
titleJAX-RS Auto Configuration
package sample.rs.service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SampleScanRestApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleScanRestApplication.class, args);
    }
}

...

"http://localhost:8080/services/sayHisayHello/ApacheCxfUser". The above code also makes Swagger docs available at "http://localhost:8080/services/swagger.json".

...