Scope request cxf jaxrs
<p>I would like to ask you a question about the scoping of the beans with cxf.
According to the documentation all the bean will in scope singleton. However I would like to have them in scope request.</p>

<p>In the doc here <a href="http://cxf.apache.org/docs/jaxrs-services-configuration.html" rel="nofollow noreferrer">http://cxf.apache.org/docs/jaxrs-services-configuration.html</a></p>

<p>I found:</p>

<blockquote>
  <p>When service classes and providers are registered this way, the default life-cycle is 'singleton'. You can override it by setting a "jaxrs.scope" parameter with the value of 'prototype' (equivalent to per-request). </p>
</blockquote>

<p>I tried thousand of stuff and I was not able to make them working:</p>

<p>Here is my web xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
    &lt;display-name&gt;CxfRestService&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;context-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/beans.xml&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;context-param&gt;
        &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/resource/log4j.properties&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;org.apache.cxf.transport.servlet.CXFServlet&lt;/servlet-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;jaxrs.scope&lt;/param-name&gt;
            &lt;param-value&gt;request&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;CXFServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;listener&gt;
        &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;listener&gt;
        &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
    &lt;/listener&gt;
&lt;/web-app&gt;
</code></pre>

<p>I did a simple test with this:</p>

<pre><code>@Path("/")
@WebService(name = "profile", targetNamespace = "")
@Named
public class ProfileCXFService {

    private String thisIsAValue;
    /**
     * Create a profile
     */
    @POST
    @Path("")
    @Produces({ MediaType.APPLICATION_JSON })
    @Consumes({ MediaType.APPLICATION_JSON })
    public Response createProfile(Profile profile){

        if(thisIsAValue == null){
            thisIsAValue = "toto";
        } else{
            return Response.serverError().entity("NOOOOOO").build();
        }
        return Response.ok().entity("YESSSSS").build();
    }
</code></pre>

<p>The first call is YESSS and the second NOOOOO.</p>

<p>I would like to have all my beans as request. Were can I find a common way to configure this. </p>

<p>In fact I do not have problem with singleton as the only fields I have are services which are as well singleton and the only moment where I need to use fields specific to the request I am doing a new MyObject. However I heard that Singleton can cause latency if the traffic grows on the server.</p>

<p>Do you have any idea of what can I do?</p>

<p>Thanks a lot in advance and best regards</p>

<p>Geoffrey</p>