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
2
votes
1 answer

Routing request to matching pages using guice servlets

I am developing inherited jsp/java ee application and I would like to introduce Guice IoC container to my application. However, I found some obstacles. I can't translate web.xml entries into guice registrations if there are more then one routing to…
0lukasz0
  • 3,155
  • 1
  • 24
  • 40
2
votes
1 answer

Display chinese character in HTML file

we have one servlet program which is using the HTML code inside the servlet program i.e HTML.append(""); HTML.append(lnTag); HTML.append(""); HTML.append(lnTag); HTML.append("java
Amit Kumar
  • 33
  • 5
2
votes
1 answer

Guice 4.0-beta5 doesn't work with Sitebricks 0.8.10

I just tried to deploy to GAE the sample HelloWorld app on Sitebricks website, using the latest versions of Guice and Sitebricks (4.0-beta5) and (0.8.10) and the injection fails. The is what the Google App Engine log shows: Uncaught exception from…
2
votes
1 answer

Guice-servlet unit testing

Background: I'm developing servlets using guice with guice-servlet frameworks. I'd like to test my servlets by: Servlet unit tests: isolating servlets from other dependencies and simulating client, by providing get/post requests Servlet integration…
Denis Itskovich
  • 4,383
  • 3
  • 32
  • 53
2
votes
0 answers

Guice - How to provide the same key differently in different scopes?

Guice users! I have a situation here and I could find a workaround, but I'm not satisfied with my solution. It's very similar to Using the provider from two different scopes, but the answer there doesn't fit my situation. I have a class like this,…
Bruno Medeiros
  • 2,251
  • 21
  • 34
2
votes
0 answers

How do I start/stop a service in a web application with Guice

I'm building a web application and I'm using the Guice Servlet extension to bootstrap everything. Following the user guide and examples I found, my web.xml has a single listener which extends GuiceServletContextListener. In my listener, I create my…
elanh
  • 1,401
  • 3
  • 19
  • 31
2
votes
1 answer

Shiro AOP with GUICE not working

I am writing a service in which i use Shiro for security. I have also incorporated Guice with it. I create the GUICE injector in a GuiceServletContextListener : //Custom Shiro Web module with defined REALM new MyShiroWebModule(this.servletContext,…
okipol
  • 1,197
  • 3
  • 11
  • 27
2
votes
2 answers

How to get current logged in user in my java web app but not in servlet context?

After get current user info I store it in session for later use, but most of the situation I need to get current user info not in a servlet context. Such as in non-servlet environment I need to call something like…
Mike
  • 3,515
  • 10
  • 44
  • 67
2
votes
2 answers

Is there a way to check if I'm inside a servlet request with Guice?

I'm writing a JUL logging Handler and I'd like to augment the logged messages with information about the current request, if we're currently handling a request. To accomplish this, I've injected a Provider into the Handler, where Thing is…
Tavian Barnes
  • 12,477
  • 4
  • 45
  • 118
2
votes
2 answers

Serve static files together with Jersey, Guice config

I do have the following configuration as a Guice module (instead of a web.xml) public class RestModule extends JerseyServletModule { @Override protected void configureServlets() { install(new JpaPersistModule("myDB")); …
Andreas Petersson
  • 16,248
  • 11
  • 59
  • 91
2
votes
1 answer

Can I do this with GUICE

Suppose I have the following classes defined: public interface A {} public class A1 implements A {} public class A2 implements A {} public class XServlet extends HttpServlet { public XServlet(T delegate){} } Additionally in one…
andrew.z
  • 1,039
  • 3
  • 15
  • 24
2
votes
1 answer

Override jersey resource with guice

I'm looking for a method to override jersey resources bounded with guice in GuiceServletContextListener. My code, which I'm trying to get working: //Define Jersey resource interface @Path("/books/{key}") public interface BookDocument { public…
speechkey
  • 625
  • 2
  • 10
  • 16
2
votes
1 answer

guice servlet is not a singleton

something awful is happening i have 2 servlets in my project - one of them simply has a post method and is responsible for handling file uploads. i recently added the other one - it has a get and a post method. here is the 2nd servlet…
sean christe
  • 879
  • 2
  • 7
  • 24
1
vote
6 answers

Vaadin Window component not fully injected with Guice

I have a very simple Vaadin application. I want to inject the main window of my Vaadin app using Guice. My problem is that my main window is injected, but none of my @Inject directives inside this main window component are processed. The full code…
1
vote
1 answer

@Schedule equivalent for Guice: execute tasks in @singleton at specified intervals

I'm using Google Guice, Guice servlet, and Jersey. I'd like to find an easy way to run scheduled jobs in the JVM. I found the following EJB example that creates "a @Singleton EJB with @Schedule method which executes in the background at specified…
JStark
  • 2,788
  • 2
  • 29
  • 37