Questions tagged [guice-servlet]

Guice's servlet extensions allow you to completely eliminate web.xml from your servlet application and take advantage of type-safe, idiomatic Java configuration of your servlet and filter components

Guice Servlet Extensions

Guice Servlet provides a complete story for use in web applications and servlet containers. Guice's servlet extensions allow you to completely eliminate web.xml from your servlet application and take advantage of type-safe, idiomatic Java configuration of your servlet and filter components.

This has advantages not only in being able to use a nicer API for configuring your web applications, but also in tying together dependency injection with web components. Meaning that your servlets and filters benefit from:

  • Constructor injection
  • Type-safe, idiomatic configuration
  • Modularization (package and distribute custom Guice Servlet libraries)
  • Guice AOP

While keeping the benefits of the standard servlet lifecycle.

References

100 questions
4
votes
2 answers

How to map a filter to a servlet using guice-servlet?

With Guice-servlet we can easily do servlet mapping like this: filter(*.jsp).through(MyFilter.class) However could anyone tell me how can i map a filter to a servlet? Reporter
Mike
  • 3,515
  • 10
  • 44
  • 67
4
votes
2 answers

Guice Injection into Business Layer of Java Web App

I have sucessfully used Guice to Inject Providers into the servlet portion of an existing java web application, however, I can't access the injectors through the business layer (non-servlet java classes) of the application. I have read up on…
oberger
  • 1,217
  • 2
  • 16
  • 31
4
votes
1 answer

How to use Guice Servlet with Wicket

After setting up my Wicket project with Guice Servlet, I get a java.lang.IllegalStateException: filter path was not configured. The filter path is configured, though. Am I missing something? web.xml
Daniel
  • 10,115
  • 3
  • 44
  • 62
4
votes
3 answers

Forwarding request to a JSP

I discovered Guice last week... I'm trying some easy tricks with it. However, I'm currently blocked... I'm trying to forward a request to a JSP in a Servlet served by an url-pattern which contains a " * ". But I receive "Error 404" all the time…
Pierre
  • 139
  • 3
  • 8
4
votes
1 answer

Swagger and Google Guice setup

I'm trying to add swagger to my project. Our setup differs a bit from the sample projects. We use guice and guice-servlet to inject and start our JerseyServletModule. Today our web.xml looks something like this
regius
  • 55
  • 6
4
votes
2 answers

Using Guice Servlet with Jetty to map paths to servlets without using a web.xml

I am struggling with getting Guice Servlet working to configure how Jetty serves web requests, in this simple case, for static pages. I have created a simple application that is supposed to map two different requests, one using GuiceServlet,…
neuronotic
  • 487
  • 7
  • 18
4
votes
1 answer

Setting up web.xml listeners and context-param using guice servlet

I'm working on a web project using guice and guice servlet. I've already setup both guice filter and listener. With this setup I can emulate web.xml filters and servlets in a servletmodule using the serve(...) and filter(...) methods. Now the…
mathiasbn
  • 881
  • 11
  • 21
4
votes
1 answer

Custom dynamic error 404 page - guice / tomcat

I'm creating a web application using guice 3.0 on a tomcat 7 server. I managed to use a static file to customize my error 404 page but now I need to customize the error 404 page using a servlet. So, in my web.xml I add those lines:
Manu
  • 493
  • 6
  • 17
3
votes
1 answer

Auto-cleared sessions with guice-persist

I'm using an environment with guice-servlet running on a tomcat and hibernate under guice-persist. The problem I've encountered is that when I use em.getReference() in one request the loaded proxy object stays in the entitymanager cache and may…
3
votes
2 answers

Session state using guice

I've some session scoped state. First idea to hold it was session scoped servlets. So I bind my servlet like this bind(Foo.class).in(ServletScopes.SESSION); But I get an exception javax.servlet.ServletException: Servlets must be bound as…
Stan Kurilin
  • 15,614
  • 21
  • 81
  • 132
3
votes
0 answers

Is there a nice way to access Guice Request scoped items from child threads and scope things locally to those threads?

I'm currently working on a product that we've set up to use guice-servlet. For each request that we receive, we spawn a bunch of worker threads, each of which go off and perform a "task". The results of those tasks are then merged to produce a…
phippsnatch
  • 186
  • 7
3
votes
1 answer

Testing a project using Guice Servlet: How to bind out-of-scope RequestScoped instances?

We have a Java web application that is instantiated using Guice and the Guice Servlet extension. The application also includes Quartz jobs that are also instantiated by Guice. I want to write unit test for these jobs. The job classes depend on other…
oberlies
  • 11,503
  • 4
  • 63
  • 110
3
votes
1 answer

Jetty can't find login.jsp when using Jersey-Guice-Shiro stack

(Update 2nd Jan 2013) I've now added all the code plus a pom.xml to github at https://github.com/AndyWi/GuiceJerseyJettyShiroExample (End update) I'm trying to add Form based authentication to my simple application using Shiro. The application uses…
AndyW
  • 101
  • 7
2
votes
1 answer

Routing sub-paths with Guice servlets

I'm using Guice to route requests in my web app, and I'd like to modularize the routing of some of the URL patterns I'll be handling. Ideally, I'd like to be able to do something like this in my…
bdonlan
  • 224,562
  • 31
  • 268
  • 324
2
votes
1 answer

When using the guice servlet extension is it possible to react to servlet destruction?

I need to do some cleanup when guice servlet is removed. Is it possible to hook into the servlet destruction when using a guice servlet? I need to use the Injector to do the cleanup work. I can override the contextDestroyed method in…
lexicalscope
  • 7,158
  • 6
  • 37
  • 57