Well it is a class annotated with CDI annotation (@Singleton) so for what I
understand the instance should be initialized by CDI container.

Look Jersey example is:

import javax.inject.Singleton;

@Path("/item")
public class ItemResource {
    @Path("content")
    public Class<ItemContentSingletonResource> getItemContentResource() {
        return ItemContentSingletonResource.class;
    }
}

@Singleton
public class ItemContentSingletonResource {
    // this class is managed in the singleton life cycle
}

2014-11-03 11:43 GMT+01:00 Romain Manni-Bucau <[email protected]>:

> Spec says "Objects returned by sub-resource locators (see Section
> 3.4.1) are expected to be
> initialized by their creator." + reading 3.4.1 not sure Class is valid
> (even if I get it could make sense).
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014-11-03 11:34 GMT+01:00 Alex Soto <[email protected]>:
> > Hi,
> >
> > I would like to create a subresource which returns a class type
> (annotated
> > with javax.injection.Singleton). The example comes from Jersey
> > documentation. Let me show you how it looks:
> >
> > @Path("/v1")
> > public class DispatcherResourceV1 {
> >
> > @Path("/chapter")
> > public Class<ChapterResourceV1> v1Chapters() {
> > return ChapterResourceV1.class;
> > }
> >  //.. and other resources
> > }
> >
> > import javax.inject.Singleton;
> > import javax.ws.rs.GET;
> > import javax.ws.rs.Path;
> > import javax.ws.rs.Produces;
> > import javax.ws.rs.core.MediaType;
> >
> > @Singleton
> > public class ChapterResourceV1 {
> >
> > @GET
> > @Path("/")
> > @Produces(MediaType.TEXT_PLAIN)
> > public String chapter() {
> > return "Hello V1";
> > }
> > }
> >
> > But running this code next log message is printed:
> >
> > WARNING: No resource methods have been found for resource class
> > java.lang.Class
> > Nov 03, 2014 11:30:14 AM org.apache.cxf.jaxrs.JAXRSInvoker invoke
> > SEVERE: No subresource locator found for path /
> >
> > Obviously it seems I am missing something but I don't know exactly what,
> > because if I change returning an class type to returning an instance it
> > works perfectly.
> >
> >
> >
> > --
> > +----------------------------------------------------------+
> >   Alex Soto Bueno
> >   www.lordofthejars.com
> > +----------------------------------------------------------+
>



-- 
+----------------------------------------------------------+
  Alex Soto Bueno - Computer Engineer
  www.lordofthejars.com
+----------------------------------------------------------+

Reply via email to