> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: Friday, October 15, 2010 8:55 AM
> To: [email protected]
> Subject: Re: Annotation to self-register service bean?
> 
> Hi David
> 
> So this time you have an external model referring to some interface
but
> this
> time
> you expect that having a "component-scan" element would help with
> finding
> concrete
> implementations of the interface ?

Again, I'm not using interfaces.  For illustration, here is an excerpt
of my context, along with a bit of the controller class (with some
information elided).

-----------
    <jaxrs:server name="MyDataServer" address="/rest">
        <jaxrs:providers>
            <ref bean="jacksonJsonProvider"/>
        </jaxrs:providers>
        <jaxrs:serviceBeans>
            <ref bean="serviceCallResultsController"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <bean id="serviceCallResultsController"
class="...ServiceCallResultsController"/>
-----------
-----------
@Controller
@Path("/...")
@Produces({"application/xml", "application/json"})
public class ServiceCallResultsController {
----------

I would never expect that I could just remove the "serviceBeans" element
and the explicit bean definition for "serviceCallResultsController" and
result in the ServiceCallResultsController class being "autoregistered"
as a service bean.  That would mean that any @Controller-annotated class
would be auto-registered, which would be bad if I had controllers which
weren't intended to be service beans.

What WOULD make some sense is if there were a new annotation, with some
name like "@JAXRSServerRegistration", whose "value" would have to
correspond to the "name" attribute of the "jaxrs:server" element.

Just so it's clear, I can see that this can't be done with the existing
code base, although I think the implementation of a BeanPostProcessor to
make this happen seems straightforward.

Do you see any value in this approach?

> I'm not sure how it can work. The provisioning of concrete
> implementations
> should be driven by a user (example, by specifying a
> jaxrs:server/serviceBeans section or registering an OSGI service -
> interface(s) plus object, etc).
> Otherwise we may have a case whereon 2 1 concrete implementation
> qualifies
> and the other one is not supposed to be used as a jaxrs resource, etc,
> if
> say we have multiple implementations in the same package being scanned
> now.
> 
> That said I'd be interested to see a concrete test webapp which
> demonstrates
> the issue and may be CXF JAXRS can get updated a bit so that external
> model
> referring to interfaces is applied to concrete implementations
> discovered by
> the scanning facility. This can be cool after all... If you can create
> a
> sample webapp or maven project and attach it to the JIRA then I'd try
> to
> look into it.
> 
> Currently one only can drop jaxrs:server/serviceBeans if the external
> model
> refers to concrete classes.
> 
> I'm away next week so will only be able to reply on the week starting
> 25th
> October
> 
> cheers, Sergey
> 
> I'm still unsure what I can do here.  I tried commenting out my
> > "serviceBeans" section and the explicit bean definition.  My
> Controller
> > has a "@Controller" annotation, and my "component-scan" element
> > specifies the parent package of the Controller's package.
> >
> > When I start up now, I see the following:
> >
> > -----------------------------
> > Oct 14, 2010 10:51:13 AM
> org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean
> > checkResources
> > SEVERE: No resource classes found
> > [main] WARN
> > org.springframework.beans.factory.support.DisposableBeanAdapter -
> > Invocation of destroy method 'shutdown' failed on bean with name
> 'cxf':
> > org.springframework.beans.factory.BeanCreationNotAllowedException:
> Error
> > creating bean with name
> > 'org.apache.cxf.buslifecycle.BusLifeCycleManager': Singleton bean
> > creation not allowed while the singletons of this factory are in
> > destruction (Do not request a bean from a BeanFactory in a destroy
> > method implementation!)
> > [main] ERROR org.springframework.web.context.ContextLoader - Context
> > initialization failed
> > org.springframework.beans.factory.BeanCreationException: Error
> creating
> > bean with name 'SunlightDataServer': Invocation of init method
> failed;
> > nested exception is
> > org.apache.cxf.service.factory.ServiceConstructionException
> >        at
> >
>
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFa
> c
> > tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
> >        at
> >
>
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFa
> c
> > tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
> > ...
> > Caused by:
> org.apache.cxf.service.factory.ServiceConstructionException
> >        at
> >
>
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBe
> a
> > n.java:132)
> > ...
> > Caused by: javax.ws.rs.WebApplicationException
> >        at
> >
>
org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJA
> X
> > RSFactoryBean.java:270)
> >        at
> >
>
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBe
> a
> > n.java:87)
> > ...
> > Oct 14, 2010 10:51:13 AM org.apache.catalina.core.StandardContext
> > listenerStart
> > SEVERE: Exception sending context initialized event to listener
> instance
> > of class org.springframework.web.context.ContextLoaderListener
> > org.springframework.beans.factory.BeanCreationException: Error
> creating
> > bean with name 'SunlightDataServer': Invocation of init method
> failed;
> > nested exception is
> > org.apache.cxf.service.factory.ServiceConstructionException
> >        at
> >
>
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFa
> c
> > tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
> >        at
> >
>
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFa
> c
> > tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
> > ...
> > Caused by:
> org.apache.cxf.service.factory.ServiceConstructionException
> >        at
> >
>
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBe
> a
> > n.java:132)
> > ...
> > Caused by: javax.ws.rs.WebApplicationException
> >        at
> >
>
org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJA
> X
> > RSFactoryBean.java:270)
> >        at
> >
>
org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBe
> a
> > n.java:87)
> > ...
> > Oct 14, 2010 10:51:13 AM org.apache.catalina.core.StandardContext
> start
> > SEVERE: Error listenerStart
> > Oct 14, 2010 10:51:13 AM org.apache.catalina.core.StandardContext
> start
> > SEVERE: Context [/SunlightDataService] startup failed due to
previous
> > errors
> > ------------------------
> >
> > None of this happens if I have the "serviceBeans" section.
> >

Reply via email to