Guice application working with AnalogWeb's Router.
public class SayHello {
public String sayHello() {
return "Hello!";
}
}
import java.net.URI;
import javax.inject.Inject;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.analogweb.ApplicationContext;
import org.analogweb.ApplicationProperties;
import org.analogweb.annotation.Route;
import org.analogweb.core.DefaultApplicationProperties;
import org.analogweb.core.Servers;
import org.analogweb.guice.GuiceApplicationContext;
@Route("/")
public class Hello {
public static void main(String... args) {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Hello.class);
bind(SayHello.class);
}
});
ApplicationContext context = GuiceApplicationContext.context(injector);
ApplicationProperties props = DefaultApplicationProperties
.properties(Hello.class.getPackage().getName());
Servers.create(URI.create("http://localhost:8080"),props,context).run();
}
@Inject
private SayHello service;
@Route
public String hello() {
return service.sayHello();
}
}