Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 2061491

Browse files
committed
Require doesnt work in routes defined on a separate file. fix jooby-project#767
1 parent 24df466 commit 2061491

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.jooby.issues;
2+
3+
import org.jooby.Jooby;
4+
import org.jooby.test.ServerFeature;
5+
import org.junit.Test;
6+
7+
public class Issue767 extends ServerFeature {
8+
9+
public static class Service {
10+
public String doWork() {
11+
return "OK";
12+
}
13+
}
14+
15+
public static class Foo extends Jooby {
16+
{
17+
get("/foo", () -> require(Service.class).doWork());
18+
}
19+
}
20+
21+
{
22+
get("/767", () -> require(Service.class).doWork());
23+
24+
use("/767", new Foo());
25+
}
26+
27+
@Test
28+
public void shouldHaveAccessFromTopApp() throws Exception {
29+
request()
30+
.get("/767")
31+
.expect("OK");
32+
}
33+
34+
@Test
35+
public void shouldHaveAccessFromSubApp() throws Exception {
36+
request()
37+
.get("/767/foo")
38+
.expect("OK");
39+
}
40+
41+
}

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
698698
*/
699699
private transient BiFunction<Stage, com.google.inject.Module, Injector> injectorFactory = Guice::createInjector;
700700

701+
private List<Jooby> apprefs;
702+
701703
/**
702704
* Creates a new {@link Jooby} application.
703705
*/
@@ -780,6 +782,10 @@ private Jooby use(final Optional<String> path, final Jooby app) {
780782
if (app.mapper != null) {
781783
this.map(app.mapper);
782784
}
785+
if (apprefs == null) {
786+
apprefs = new ArrayList<>();
787+
}
788+
apprefs.add(app);
783789
return this;
784790
}
785791

@@ -2755,6 +2761,11 @@ private Injector bootstrap(final Config args,
27552761
};
27562762

27572763
Injector injector = injectorFactory.apply(stage, joobyModule);
2764+
if (apprefs != null) {
2765+
apprefs.forEach(app -> app.injector = injector);
2766+
apprefs.clear();
2767+
apprefs = null;
2768+
}
27582769

27592770
onStart.addAll(0, finalEnv.startTasks());
27602771
onStarted.addAll(0, finalEnv.startedTasks());

0 commit comments

Comments
 (0)