> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Friday, August 05, 2016 3:05 AM
> To: [email protected]
> Subject: Re: Why is CXF creating a new instance of my controller
> for each request?
> 
> Hi David
> 
> By default JAX-RS assumes a service lifecycle is per-request.
> When one uses CXFServlet directly it is nearly always a singleton
> unless
> a user specifies a non-singleton scope in Spring.
> 
> So I'd need to configure it somehow at the Tomee level, I've asked
> at
> #openejb, here is what Romain (@rmannibucau) said:
> 
> Either disable a Tomee jaxrs subsystem classpath scanning to avoid
> a
> double scanning
> or
> use JAX-RS Application.getSingleton
> or
> @ApplicationScoped @javax.ejb.Singleton and @javax.inject.Singleton
> (but
> this one is a bit slower casue the lookup is done per invocation
> where
> @AppScoped is cached)

Ah.  I had already made it a @Singleton, I'll try adding @ApplicationScoped.

> By the way, I saw at "#openejb" a user who I thought might've been
> yourself. If it is indeed the case then please talk to Romain who
> is the
> TomEE expert who can always help.

Yeah, that's me.  I'll review the issue there.

> On 04/08/16 18:35, KARR, DAVID wrote:
> > I'm building a new CXF/JAX-RS/Spring app based on one that I
> built a few years ago, but with the latest versions of CXF and
> Spring (3.1.7 and 4.3.2, respectively).
> >
> > I finally thought I had gotten my controller, service, and DAO
> all wired together, but then I noticed that when I got into the
> controller method after handling a web request, the service object
> was null, even though I saw the setter breakpoint being hit.  I
> then discovered that CXF appears to be creating a new instance of
> the controller for every request, and the controller instance that
> it uses isn't wired up.
> >
> > I'm running this in TomEE 7.0.1.  The old app was running in
> WebLogic.
> >
> > When I hit the breakpoint in the controller constructor after
> sending the request, I see the following stacktrace:
> >
> > ---------------
> > WebProjController.<init>() line: 44
> > NativeConstructorAccessorImpl.newInstance0(Constructor<?>,
> Object[]) line: not available [native method]
> > NativeConstructorAccessorImpl.newInstance(Object[]) line: not
> available
> > DelegatingConstructorAccessorImpl.newInstance(Object[]) line: not
> available
> > Constructor<T>.newInstance(Object...) line: not available
> > CdiResourceProvider$DefaultBeanCreator.newInstance() line: 315
> > CdiResourceProvider$DefaultBeanCreator.create() line: 321
> >
> OpenEJBPerRequestPojoResourceProvider(CdiResourceProvider).getInsta
> nce(Message) line: 171
> > CxfRsHttpListener.getServiceObject(Message) line: 1036
> > CxfRsHttpListener.access$200(CxfRsHttpListener, Message) line:
> 142
> > CxfRsHttpListener$4.getServiceObject(Message) line: 909
> >
> CxfRsHttpListener$4(AbstractValidationInterceptor).handleMessage(Me
> ssage) line: 59
> > PhaseInterceptorChain.doIntercept(Message) line: 308
> > ChainInitiationObserver.onMessage(Message) line: 121
> > ---------------
> >
> > Any idea how to make this use the existing Spring singleton
> instead of creating a new instance?
> >
> 
> 
> --
> Sergey Beryozkin
> 
> Talend Community Coders
> http://coders.talend.com/

Reply via email to