Last active
December 15, 2015 22:30
-
-
Save ilopmar/a55af3346aaa788c632d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example | |
| import ratpack.guice.Guice | |
| import ratpack.server.RatpackServer | |
| public class MyApp { | |
| public static void main(String[] args) throws Exception { | |
| RatpackServer.start { spec -> | |
| spec.registry { | |
| Guice.registry { r -> | |
| r.bind(MyService.class) | |
| } | |
| } | |
| .handlers { chain -> | |
| chain.get { ctx -> | |
| MyService myService = ctx.get(MyService.class) | |
| myService.myMethod() | |
| ctx.render("Finished!") | |
| } | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package example; | |
| import ratpack.guice.Guice; | |
| import ratpack.server.RatpackServer; | |
| public class MyApp { | |
| public static void main(String[] args) throws Exception { | |
| RatpackServer.start(spec -> spec | |
| .registry(Guice.registry(r -> r | |
| .bind(MyService.class) | |
| )) | |
| .handlers(chain -> chain | |
| .get(ctx -> { | |
| MyService myService = ctx.get(MyService.class); | |
| myService.myMethod(); | |
| ctx.render("Finished"); | |
| }) | |
| )); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example | |
| class MyService { | |
| void myMethod() { | |
| System.out.println("calling myMethod"); | |
| } | |
| } |
Author
Yes, just change to
public class MyApp {
public static void main(String[] args) throws Exception {
RatpackServer.start { spec ->
spec.registry(
Guice.registry { r ->
r.bind(MyService.class)
}
)
.handlers { chain ->
chain.get { ctx ->
MyService myService = ctx.get(MyService.class)
myService.myMethod()
ctx.render("Finished!")
}
}
}
}
}
Author
Excellent! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I run the
MyApp.javaapplication everything works fine. I can see the messagecalling myMethodin the console and theFinishedmessage rendered in the browser.If I run the
MyApp.groovyapplication I get this error:Any idea why this happens?