Created
December 5, 2016 07:13
-
-
Save mgenov/969ee05060815b01fc4be6419d4ab825 to your computer and use it in GitHub Desktop.
Jetty Server using Guice
This file contains 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
public class Jetty { | |
private final Server server; | |
public Jetty(int port) { | |
this.server = new Server(port); | |
} | |
public void start() { | |
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); | |
context.setContextPath("/"); | |
context.addServlet(DefaultServlet.class, "/"); | |
context.addFilter(GuiceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.INCLUDE)); | |
context.addEventListener(new GuiceServletContextListener() { | |
@Override | |
protected Injector getInjector() { | |
return Guice.createInjector(new AppModule()); | |
} | |
}); | |
server.setHandler(context); | |
try { | |
server.start(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment