Skip to content

Commit

Permalink
Merge pull request #778 from jooby-project/767
Browse files Browse the repository at this point in the history
Require doesnt work in routes defined on a separate file. fix #767
  • Loading branch information
jknack authored May 21, 2017
2 parents 7a288e0 + 2061491 commit bfb7a9d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
41 changes: 41 additions & 0 deletions coverage-report/src/test/java/org/jooby/issues/Issue767.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jooby.issues;

import org.jooby.Jooby;
import org.jooby.test.ServerFeature;
import org.junit.Test;

public class Issue767 extends ServerFeature {

public static class Service {
public String doWork() {
return "OK";
}
}

public static class Foo extends Jooby {
{
get("/foo", () -> require(Service.class).doWork());
}
}

{
get("/767", () -> require(Service.class).doWork());

use("/767", new Foo());
}

@Test
public void shouldHaveAccessFromTopApp() throws Exception {
request()
.get("/767")
.expect("OK");
}

@Test
public void shouldHaveAccessFromSubApp() throws Exception {
request()
.get("/767/foo")
.expect("OK");
}

}
11 changes: 11 additions & 0 deletions jooby/src/main/java/org/jooby/Jooby.java
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
*/
private transient BiFunction<Stage, com.google.inject.Module, Injector> injectorFactory = Guice::createInjector;

private List<Jooby> apprefs;

/**
* Creates a new {@link Jooby} application.
*/
Expand Down Expand Up @@ -780,6 +782,10 @@ private Jooby use(final Optional<String> path, final Jooby app) {
if (app.mapper != null) {
this.map(app.mapper);
}
if (apprefs == null) {
apprefs = new ArrayList<>();
}
apprefs.add(app);
return this;
}

Expand Down Expand Up @@ -2755,6 +2761,11 @@ private Injector bootstrap(final Config args,
};

Injector injector = injectorFactory.apply(stage, joobyModule);
if (apprefs != null) {
apprefs.forEach(app -> app.injector = injector);
apprefs.clear();
apprefs = null;
}

onStart.addAll(0, finalEnv.startTasks());
onStarted.addAll(0, finalEnv.startedTasks());
Expand Down

0 comments on commit bfb7a9d

Please sign in to comment.