jooby icon indicating copy to clipboard operation
jooby copied to clipboard

jooby:spec does not find routes specified in modules

Open ajcamilo opened this issue 9 years ago • 4 comments

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.

ajcamilo avatar Apr 27 '17 16:04 ajcamilo

yea, doesn't work and hard to implement :(

jknack avatar Apr 27 '17 17:04 jknack

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.

ajcamilo avatar Apr 27 '17 17:04 ajcamilo

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.

jknack avatar Apr 27 '17 18:04 jknack

sounds good and works

thanks :)

ajcamilo avatar Apr 28 '17 17:04 ajcamilo