On Wed, Aug 28, 2013 at 5:24 PM, Sergey Beryozkin <[email protected]> wrote: > Hi > > On 28/08/13 10:44, Thibaut Robert wrote: >> >> Hi, >> >> I have some jax-rs service beans deployed via Spring. I use the >> jaxrs:server tag with the beanNames attribute to specify my bean. My >> beans are in a custom spring scope. >> >> Everything works fine, except that I notice that both Spring and cxf >> calls my @PostConstruct and @PreDestroy methods. I think this is a bit >> confusing. As cxf SpringResourceFactory delegate the resource >> lifecycle to spring, why is it calling itself the lifecycle methods ? >> >> In my case, the @Postconstruct is called twice at the first request >> (by spring then cxf). Then once per request (by cxf), whereas it is >> using an already existing instance. I would prefer cxf doesn't call >> the methods at all. >> > I think I added it in a 'copy-and-paste' kind of fashion, the runtime would > release a current service instance and if it is a per-request instance > explicitly managed by the runtime then it makes sense, but I can see now it > may cause side-effects, I'll make SpringResourceFactory calling lifecycle > methods only if requested by the user, in meantime, the workaround is to > register a custom SpringResourceFactory which will ignore release calls
I am just wondering if there is a use case where calling the lifecycle method is usefull. Even a per request instance, if you put it in request scope, the methods will be called by spring. Maybe if you use prototype scope ? But in my view, the lifecycle has to be managed by the container owning the bean, which is always spring with this factory. For the moment I will either use your workaround, or declare my lifecycle methods in my spring xml file. Thanks for kind support! Thibaut > Cheers, Sergey > >> Regards, >> Thibaut >> >
