Hi Ivan I've commented at [1] and suggested moving a @Context method into its own interface. In meantime, I managed to get rid of the exception by fixing the model description a bit.
You have quite a complex configuration :-), which involved describing GenericRestServiceImpl as the JAX-RS resource via an external model and then you also inject GenericRestServiceImpl explicitly (as a priorityService). What actually happens in this case is that GenericRestServiceImpl is instantiated twice, once by the CXF runtime processing the model and another one - by Spring. The second one is most likely ignored by CXF - you may want to check the logs, but the endpoint is still created because the one described by the model is recognized as a root resource class. Using the external model makes sense in some specific cases: - code modification is not possible or desirable (1) - one have an interface with concrete implementations coming and going all the time and importing JAX-RS annotations might seem to be 'intrusive' a bit, i.e., (D)OSGI case. (2) - @Path values/etc can change often enough thus the cost of modifying the existing code is deemed more expensive then modifying an external XML file and updating the @path attribute. - JAXRS & JAX-WS combined, WSDL-first case: we can not add explicit annotation to the interfaces generated from the WSDL as they will be lost during the next re-genaration, so applying the model works. If say case 1 or 2 are the one you'd like to pursue then using models is a good idea, if not then you might want to consider just add JAX-RS annotations and simplify your configuration :-). Either way, in your case, the model should reference an *interface*, IRestService, which is implemented by GenericRestServiceImpl. This will let you say to have multiple JAX-RS endpoints all sharing the same model, bbut with multiple implementations of IRestService. So try updating the model first and the exception should be gone, next, if injected contexts are null, then move the setters them to the dedicated interface, and finally, try enforcing the CGLIB proxification, I'm more or less sure it's not a CXF issue, it's probably confused at the moment by the fact two GenericRestServiceImpl are created. Hope it works, Sergey [1] https://issues.apache.org/jira/browse/CXF-3418 On Thu, Mar 24, 2011 at 3:08 PM, Sergey Beryozkin <[email protected]>wrote: > Hi Ivan > > As you can imagine, it's impossible for me to tell where the problem is, so > either create a JIRA and attach a test project or do some debugging > > thanks, Sergey > > > On Thu, Mar 24, 2011 at 2:58 PM, Ivan Vitoria Sanchez < > [email protected]> wrote: > >> Hi Sergey, >> >> I guess you're referencing to javax.ws.rs.core.Context, aren't you? >> >> The MobilityUserRestService extends from "GenericRestServiceImpl<T extends >> GenericBean, PK extends Long>", which implements "IRestService<T, PK>". >> The >> MobilityUserRestService has just one more method, and now I've created an >> interface with this method in order to have all methods within an >> interface >> (IRestService included) with the @Context annotation, but it still >> fails... >> >> >> >> Ivan >> >> -----Mensaje original----- >> De: Sergey Beryozkin [mailto:[email protected]] >> Enviado el: jueves, 24 de marzo de 2011 13:51 >> Para: [email protected] >> Asunto: Re: CXF Services and Transactions >> >> Hi Ivan >> >> On Thu, Mar 24, 2011 at 12:38 PM, Ivan Vitoria Sanchez < >> [email protected]> wrote: >> >> > Hi Sergey, >> > >> > >> > >> > I've tried through both AOP and annotation-driven techniques but the >> result >> > is the same. What do you mean with "no root resources have been found"? >> > >> > >> I thought the problem could be to do with the fact that the >> MobilityUserRestService was not recognized after being proxified. >> >> >> > >> > >> > This is the piece of the spring context configuration >> (DAO/Hibernate/JAXB >> > beans are omitted): >> > >> > >> > >> It appears the problem occurs during the initial injection of the TL >> context >> proxies. Does MobilityUserRestService has some @Context annotated fields >> or >> methods ? You just have to introduce a dedicated interface and have >> @Context >> methods on that interface - this usually works with AOP, in your case it >> should... >> >> Let me know please if you can make it work >> Sergey >> >> >> > >> > <!-- Annotation Driven Technique >> > >> > <tx:annotation-driven transaction-manager="mobilityTransactionManager" >> /> >> > >> > --> >> > >> > >> > >> > <bean id="mobilityTransactionManager" >> > class="org.springframework.orm.hibernate3.HibernateTransactionManager"> >> > >> > <property name="sessionFactory" ref="mobilitySessionFactory" /> >> > >> > </bean> >> > >> > >> > >> > <!-- AOP Technique --> >> > >> > <tx:advice id="txAdvice" >> > transaction-manager="mobilityTransactionManager"> >> > >> > <tx:attributes> >> > >> > <tx:method name="*" propagation="REQUIRED" /> >> > >> > </tx:attributes> >> > >> > </tx:advice> >> > >> > <aop:config> >> > >> > <aop:pointcut id="serviceMethods" expression="execution(* >> > com.ica.mobility.mobile.service.generic.GenericRestServiceImpl.*(..))"/> >> > >> > <aop:advisor advice-ref="txAdvice" >> pointcut-ref="serviceMethods"/> >> > >> > </aop:config> >> > >> > >> > >> > >> > >> > <!-- Generic JAX-RS server--> >> > >> > <jaxrs:server id="genericServer" >> > modelRef="classpath:/WEB-INF/model/GenericModel.xml" abstract="true"> >> > >> > <jaxrs:features> >> > >> > <cxf:logging/> >> > >> > </jaxrs:features> >> > >> > <jaxrs:inInterceptors> >> > >> > <ref bean="gzipInInterceptor" /> >> > >> > </jaxrs:inInterceptors> >> > >> > <jaxrs:outInterceptors> >> > >> > <ref bean="gzipOutInterceptor" /> >> > >> > </jaxrs:outInterceptors> >> > >> > <jaxrs:properties> >> > >> > <entry key="attachment-directory" value="/temp/mobility"/> >> > >> > <entry key="attachment-memory-threshold" value="409600"/> >> > >> > </jaxrs:properties> >> > >> > <jaxrs:providers> >> > >> > <ref bean="jaxbElementProvider" /> >> > >> > </jaxrs:providers> >> > >> > </jaxrs:server> >> > >> > >> > >> > <!-- Generic Service --> >> > >> > <bean id="genericService" >> > class="com.ica.mobility.mobile.service.generic.GenericRestServiceImpl" >> > abstract="true"> >> > >> > <property name="daoFactory" ref="daoFactory" /> >> > >> > </bean> >> > >> > >> > >> > <!-- Specific REST server --> >> > >> > <bean id="userServer" parent="genericServer"> >> > >> > <property name="modelRef" >> > value="classpath:/WEB-INF/model/MobilityUserModel.xml" /> >> > >> > <property name="address" value="/mobilityusers" /> >> > >> > <property name="serviceBeans"> >> > >> > <bean id="userService" >> > class="com.ica.mobility.mobile.service.MobilityUserRestService" >> > parent="genericService"> >> > >> > <constructor-arg >> > value="com.ica.mobility.model.bean.MobilityUser"/> >> > >> > </bean> >> > >> > </property> >> > >> > </bean> >> > >> > >> > >> > And the whole log of the exception: >> > >> > >> > >> > org.springframework.beans.factory.BeanCreationException: Error creating >> > bean >> > with name 'userServer' defined in ServletContext resource >> > [/WEB-INF/applicationContext.xml]: Invocation of init method failed; >> nested >> > exception is org.apache.cxf.service.factory.ServiceConstructionException >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory >> > .initializeBean(AbstractAutowireCapableBeanFactory.java:1412) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory >> > .doCreateBean(AbstractAutowireCapableBeanFactory.java:519) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory >> > .createBean(AbstractAutowireCapableBeanFactory.java:456) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(Ab >> > stractBeanFactory.java:291) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSi >> > ngleton(DefaultSingletonBeanRegistry.java:222) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(Abst >> > ractBeanFactory.java:288) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(Abstra >> > ctBeanFactory.java:190) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInst >> > antiateSingletons(DefaultListableBeanFactory.java:574) >> > >> > at >> > >> > >> >> org.springframework.context.support.AbstractApplicationContext.finishBeanFac >> > toryInitialization(AbstractApplicationContext.java:895) >> > >> > at >> > >> > >> >> org.springframework.context.support.AbstractApplicationContext.refresh(Abstr >> > actApplicationContext.java:425) >> > >> > at >> > >> > >> >> org.springframework.web.context.ContextLoader.createWebApplicationContext(Co >> > ntextLoader.java:276) >> > >> > at >> > >> > >> >> org.springframework.web.context.ContextLoader.initWebApplicationContext(Cont >> > extLoader.java:197) >> > >> > at >> > >> > >> >> org.springframework.web.context.ContextLoaderListener.contextInitialized(Con >> > textLoaderListener.java:47) >> > >> > at >> > >> > >> >> org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java: >> > 3972) >> > >> > at >> > >> org.apache.catalina.core.StandardContext.start(StandardContext.java:4467) >> > >> > at >> > >> > >> >> org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:7 >> > 91) >> > >> > at >> > org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) >> > >> > at >> > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546) >> > >> > at >> > >> > >> >> org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637) >> > >> > at >> > org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:521) >> > >> > at >> > org.apache.catalina.startup.HostConfig.check(HostConfig.java:1359) >> > >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > >> > at >> > >> > >> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 >> > ) >> > >> > at >> > >> > >> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl >> > .java:25) >> > >> > at java.lang.reflect.Method.invoke(Method.java:597) >> > >> > at >> > >> > >> >> org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297 >> > ) >> > >> > at >> > >> > >> >> com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanSer >> > verInterceptor.java:836) >> > >> > at >> > com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761) >> > >> > at >> > >> org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1500) >> > >> > at >> > >> org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:849) >> > >> > at >> > >> org.apache.catalina.manager.ManagerServlet.doGet(ManagerServlet.java:351) >> > >> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) >> > >> > at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) >> > >> > at >> > >> > >> >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application >> > FilterChain.java:290) >> > >> > at >> > >> > >> >> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh >> > ain.java:206) >> > >> > at >> > >> > >> >> org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter >> > .java:199) >> > >> > at >> > >> > >> >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application >> > FilterChain.java:235) >> > >> > at >> > >> > >> >> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh >> > ain.java:206) >> > >> > at >> > >> > >> >> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja >> > va:233) >> > >> > at >> > >> > >> >> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja >> > va:191) >> > >> > at >> > >> > >> >> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase >> > .java:558) >> > >> > at >> > >> > >> >> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127 >> > ) >> > >> > at >> > >> > >> >> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102 >> > ) >> > >> > at >> > >> > >> >> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java >> > :109) >> > >> > at >> > >> >> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) >> > >> > at >> > >> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) >> > >> > at >> > >> > >> >> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http >> > 11Protocol.java:588) >> > >> > at >> > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) >> > >> > at java.lang.Thread.run(Thread.java:619) >> > >> > Caused by: org.apache.cxf.service.factory.ServiceConstructionException >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.ja >> > va:132) >> > >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > >> > at >> > >> > >> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 >> > ) >> > >> > at >> > >> > >> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl >> > .java:25) >> > >> > at java.lang.reflect.Method.invoke(Method.java:597) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory >> > .invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1536) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory >> > .invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) >> > >> > at >> > >> > >> >> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory >> > .initializeBean(AbstractAutowireCapableBeanFactory.java:1409) >> > >> > ... 48 more >> > >> > Caused by: javax.ws.rs.WebApplicationException >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.utils.InjectionUtils.reportServerError(InjectionUtils.j >> > ava:378) >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.utils.InjectionUtils.injectThroughMethod(InjectionUtils >> > .java:264) >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.utils.InjectionUtils.injectContextProxies(InjectionUtil >> > s.java:787) >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.injectContexts(JAXRSServerFactor >> > yBean.java:219) >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.updateClassResourceProviders(JAX >> > RSServerFactoryBean.java:240) >> > >> > at >> > >> > >> >> org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.ja >> > va:91) >> > >> > ... 55 more >> > >> > >> > >> > Ivan >> > >> > >> > >> > De: Sergey Beryozkin [mailto:[email protected]] >> > Enviado el: jueves, 24 de marzo de 2011 13:03 >> > Para: [email protected] >> > CC: Ivan Vitoria Sanchez >> > Asunto: Re: CXF Services and Transactions >> > >> > >> > >> > Hi Ivan >> > >> > I've seen users doing it successfully. Is it a model-driven case ? I'm >> > presuming the exception is to do with the fact no root resources have >> been >> > found ? What does the log say ? >> > >> > Cheers, Sergey >> > >> > On Thu, Mar 24, 2011 at 11:45 AM, Ivan Vitoria Sanchez >> > <[email protected]> wrote: >> > >> > Hello, >> > >> > >> > >> > I have some JAX-RS servers configured through Spring. Also, i'm using >> > Hibernate DAOs and the OpenSessionInViewFilter of Spring-ORM. I have no >> > problem when I add the @Transactional annotation to the DAO layer, but i >> > would like to have the REST methods in the same transaction, so i've >> > annoated the services. But I can't do it, neither annotating the >> interface >> > nor the classes. A ServiceConstructionException is throwed as soon as I >> > add >> > the @Transactional to the service... >> > >> > >> > >> > CXF Version: 2.3.2 >> > >> > Spring version: 3.0.3 >> > >> > Hibernate version: 3 >> > >> > >> > >> > Thanks in advance! >> > >> > >> > >> > Ivan >> > >> > >> > >> > >> > -- > Sergey Beryozkin >> > >> > Application Integration Division of Talend <http://www.talend.com> >> > http://sberyozkin.blogspot.com >> > >> > >> >>
