GWT ServiceLocator with multi-module maven project

557 Views Asked by At

I've a multi-module GWT project and I'd like to use ServiceLocators. I have 3 modules:

  • "client" depends on shared
  • "shared"
  • "server" depends on shared

I wrote the ServiceLocator like this:

public class TreeServiceLocator implements ServiceLocator {
    public Object getInstance(Class<?> clazz) {
        return new TreeService();
    }
}

and placed this class in the "shared" module because ServiceLocator has the package com.google.gwt.requestfactory.shared. However, when I compile this throws an error because TreeService is implemented in the "server" module since I need it to return beans from the server and interact with Spring, etc.

In which module should I implement the TreeServiceLocator? Also, maven will throw a circular dependency error if I try to include "server" from the "shared" module.

Thank you!

1

There are 1 best solutions below

0
On BEST ANSWER

Place the TreeServiceLocator in the server package, and use a @ServiceName annotation instead of @Service. These annotations have the same effect, but the former uses string literals instead of class literals. This will avoid problems with the GWT compile if the server types aren't available on the classpath of the GWT compiler.