Guice Servlets

67 views
Skip to first unread message

Naresh Janarthanam

unread,
Jul 10, 2015, 6:04:20 AM7/10/15
to google...@googlegroups.com
web.xml configuration for servlets can also be removed using javax.servlet.annotation.WebServlet. Any thoughts, if other Guice servlet module functionalities like Scopes and filter will be supported by standard Java.

Thomas Broyer

unread,
Jul 10, 2015, 7:20:10 AM7/10/15
to google...@googlegroups.com


On Friday, July 10, 2015 at 12:04:20 PM UTC+2, Naresh Janarthanam wrote:
web.xml configuration for servlets can also be removed using javax.servlet.annotation.WebServlet. Any thoughts, if other Guice servlet module functionalities like Scopes and filter will be supported by standard Java.

Filters can similarly be declared with javax.servlet.annotation.WebFilter, and "standard Java" (JavaEE) has "resource injection" (used with JNDI), and CDI as a total replacement of Guice, with ApplicationScoped, SessionScoped, ConversationScoped, TransactionScoped, and RequestScoped.
If you want to use Guice, then you have to use Guice's ServletModule though, or your servlets and filters won't be injected (unless you inject them yourself, e.g. in their init(), retrieving the Injector out of the ServletContext). I think the goal of Guice Servlets is not to "remove the servlet configuration from the web.xml", this is merely a side-effect of the constraint that Guice must instantiate them as there's no standard listener where it could hook to do the injection, and as a further side-effect that also allows registering servlet and filters using regexps instead of URL patterns.
Reply all
Reply to author
Forward
0 new messages