Class xxx does not contain a public constructor needed to autobuild when xxx become a Tapestry Service

StackOverflow https://stackoverflow.com/questions/14389232

  •  16-01-2022
  •  | 
  •  

I'm discovering the wonderful integration work made by Tynamo's team between Tapestry and Resteasy .

I'm trying to activate Liveclass Reloading on webservices. As per doc says :

Documentation

The only thing you need to do to enable live class reloading for your REST services is to bind them as regular Tapestry IoC services and contribute them to javax.ws.rs.core.Application.class. Read more about how service implementation reloading works in: http://tapestry.apache.org/reload.html

Here is an example from the tapestry-resteasy test suite.

public static void bind(ServiceBinder binder)
{
    binder.bind(ReloadableEchoResource.class, ReloadableEchoResourceImpl.class);
}

@Contribute(javax.ws.rs.core.Application.class)
public static void configureRestResources(Configuration<Object> singletons, ReloadableEchoResource reloadableEchoResource)
{
    singletons.add(reloadableEchoResource);
}

My Own Work

This is exactly what I'm doing (well ... hmmm at least I believe that it is ;D):

My binding

public static void bind(ServiceBinder binder)
{
    binder.bind(PushMessageService.class, GCMPushMessageServiceImpl.class);
    binder.bind(UserService.class, HibernateUserServiceImpl.class);
    binder.bind(IUserResource.class, UserResourceImpl.class);

}

/**
 * Contributions to the RESTeasy main Application, insert all your RESTeasy singletons services here.
 */
@Contribute(javax.ws.rs.core.Application.class)
public static void configureRestResources(Configuration<Object> singletons, IUserResource userResource)
{
    singletons.add(userResource);
}

My Interface

@Path("/user")
public interface IUserResource {

    /**
     * Lecture de tous les utilisateurs
     * 
     * @return une List des utilisateurs existants
     */
    @GET
    @Produces("application/json")
    public abstract List<User> getAllDomains();

Error

But when I start my app, I obtain this message :

HTTP ERROR 500

Problem accessing /user. Reason:

Exception constructing service 'ResteasyRequestFilter': Error building service proxy for service 'Application' (at org.tynamo.resteasy.Application(Collection) (at Application.java:14) via org.tynamo.resteasy.ResteasyModule.bind(ServiceBinder) (at ResteasyModule.java:31)): Error invoking service contribution method org.tynamo.resteasy.ResteasyModule.javaxWsRsCoreApplication(Configuration, ObjectLocator, ResteasyPackageManager, ClassNameLocator): Class com.sopragroup.ecommerce.mobile.rest.IUserResource does not contain a public constructor needed to autobuild.

Caused by:

java.lang.RuntimeException: Exception constructing service 'ResteasyRequestFilter': Error building service proxy for service 'Application' (at org.tynamo.resteasy.Application(Collection) (at Application.java:14) via org.tynamo.resteasy.ResteasyModule.bind(ServiceBinder) (at ResteasyModule.java:31)): Error invoking service contribution method org.tynamo.resteasy.ResteasyModule.javaxWsRsCoreApplication(Configuration, ObjectLocator, ResteasyPackageManager, ClassNameLocator): Class com.sopragroup.ecommerce.mobile.rest.IUserResource does not contain a public constructor needed to autobuild.
    at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:75)
    at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:54)

It's quite like the autobinding don't works (indeed I do think it is). Obviously, when I try to without creating an interface and binding, it works like a charm.

Can someone give me a clue ?

有帮助吗?

解决方案

I think the issue is that tapestry-resteasy is trying to autobuild IUserResource because it's in the "rest" package.

Here is a very important documentation line that you may have missed:

One more thing: DO NOT put this service in the autodiscovery package.

This is an important line and it was somehow hidden in the docs so I added a warning to make it more visible for future users: http://docs.codehaus.org/pages/diffpagesbyversion.action?pageId=151847035&selectedPageVersions=24&selectedPageVersions=23

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top