jooby:spec does not find routes specified in modules
If you have some module with:
public class UsersManagement implements Jooby.Module {
@Override
public void configure(Env env, Config config, Binder binder) throws Throwable {
binder.bind(UsersService.class);
env.router().use("/api/users")
.get(req -> {
UsersService service = req.require(UsersService.class);
List<User> users = service.getUsers();
return users;
});
}
}
and in the app code
...
use(new UsersManagement());
...
The route "/api/users" is not included in the jooby:spec goal
I also tried executing this code:
public static void main(String[] args){
//run(App::new, args);
App app = new App();
System.out.println(exportRoutes(app));
}
The route is not listed and while debugging, the configure method of the Module was not called.
yea, doesn't work and hard to implement :(
do you have any suggestion how can I "modularize" my project and still have the spec functionality?
One solution is to add a method buildRoute(Router router) to the Jooby.Module interface. This way you can separate the configure of the module of the route definition.
Unfortunately, buildRoute isn't an option. For me routes from modules are usually system/low level routes.
You can compose/modularize your application using Jooby instances without a main method (usually).
class Bar extends Jooby {
{
// your bar routes
}
}
class Foo extends Jooby {
{
use(new Bar()); // optionally mount bar to a path: use("/sub-system", new Bar());
}
public static void main (String[] args) {
run(Foo::new, args);
}
}
This is (or should be) supported by spec module.
btw: going to redo spec module in next major release, the doc support is kind of weak today and need to be better but also optional.
sounds good and works
thanks :)