Versions Compared

Key

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

...

  • 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, the 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 create the JAX-RS runtime to handle the resource class lifecycle of resource classes (for example, it might be the case that your resource class can be is created by other containers like such as Spring), you can do following:
    Code Block
    java
    java
            JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
            BookStore bs = new BookStore();
            sf.setServiceBeans(bs);
            sf.setAddress("http://localhost:9080/");
    
            sf.create();     
    

Configuring the service in container with Spring configuration file.

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jaxrs="http://cxf.apache.org/jaxrs"
  xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">

  <import resource="classpath:META-INF/cxf/cxf.xml" />
  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
  <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  
  <jaxrs:server id="bookservicecustomerService" address="/">
    <jaxrs:serviceBeans>
      <ref<bean beanclass="bookstore"demo.jaxrs.server.CustomerService" />
    </jaxrs:serviceBeans>		   
  </jaxrs:server>
  <bean id="bookstore" scope="prototype" class="org.apache.cxf.systest.jaxrs.BookStore">
  </bean>

</beans>