Versions Compared

Key

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

...

You can create a JAX-RS RESTful service by using JAXRSServerFactoryBean:

Code Block
java
java

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

...

  • The JAXRSServerFactoryBean creates a Server inside CXF which starts listening for requests on the URL specified.
  • By default, the JAX-RS runtime is responsible for the lifecycle of resource classes, default lifecycle is per-request. You can set the lifecycle to singleton by using following line:
    Code Block
    java
    java
    
    
           sf.setResourceProvider(BookStore.class, new SingletonResourceProvider());
    
  • If you prefer not to let the JAX-RS runtime to handle the resource class lifecycle for you (for example, it might be the case that your resource class is created by other containers such as Spring), you can do following:
    Code Block
    java
    java
    
            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
            BookStoreCustomerService bscs = new BookStoreCustomerService();
            sf.setServiceBeans(bscs);
            sf.setAddress("http://localhost:9080/");
            sf.create();     
    

...