Search code examples
mavenserviceinterfacetapestry

Making services in Tapestry 5: No service implements the interface


I'm developing my first Tapestry application with a login system based on a Hibernate database.

On one page with a session object, I want to call my Authenticator service class, which also gets the session injected and does some stuff. My problem is, I can't get any services to run, it's been very frustrating, despite me following simple guides like this one: http://code.google.com/p/shams/wiki/Service

In my services package, I got the Authenticator.java and AuthenticatorImpl.java interface and implemented class. In the AppModule class, I call

    binder.bind(Authenticator.class, AuthenticatorImpl.class);

And in my page 'ShowAllUsers' I inject my Authenticator service object:

...
public class ShowAllUsers{
@Inject
private Session session;

@Inject
private Authenticator authenticator;
...
}

But when I load the page on my server, I receive following error:

org.apache.tapestry5.ioc.internal.OperationException
Error obtaining injected value for field de.webtech2.pages.user.ShowAllUsers.authenticator: No service implements the interface de.webtech2.services.Authenticator.

trace:
- Creating instantiator for component class de.webtech2.pages.user.ShowAllUsers
- Running component class transformations on de.webtech2.pages.user.ShowAllUsers
- Injecting field de.webtech2.pages.user.ShowAllUsers.authenticator

But my AppModule does bind the class to the interface successfully. In the Maven build console I can read "Authenticator: DEFINED" and if I try to bind it in another module, it complains because it's bound in AppMopule already.

Why doesn't tapestry see the implementation? What am I doing wrong?


Solution

  • I haven't solved the issue itself but I found a workaround that fixes it. As you might find on the internet, Tapestry allows for auto-reloading classes. Pages and components do work fine, services have some limitations -- this is where there seem to arise issues. Tomcat doesn't link the interface to the implementation.

    Fix: A simple restart of eclipse solves this. Meh. (This also fixes the "method not found" error if you added a new method to an existing service)

    Also, when I execute mvn clean, everything gets screwed many times over. Eclipse can no longer resolve the simplest class and package references. Classes in the same package can no longer be found, or references to the javax.internet package lead into eternal nothingness -- whereas everything was working just fine a moment ago.

    Fix:

    Right-click eclipse project -> Properties -> Maven
    

    Tick the checkbox for "Resolve dependencies from Workspace projects" and hit Apply. If it is already checked, uncheck -> apply, then recheck -> apply. Eclipse should go sane again -- until next time...