Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4023040
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:33:00+00:00 2026-05-20T10:33:00+00:00

I create guice servlet like this: public class GuiceApplicationServlet extends AbstractApplicationServlet { protected Provider<Application>

  • 0

I create guice servlet like this:

public class GuiceApplicationServlet extends AbstractApplicationServlet {

    protected Provider<Application> applicationProvider;

    public GuiceApplicationServlet() {
        System.out.println("TTest");
    }

    @Inject
    public GuiceApplicationServlet(Provider<Application> applicationProvider) {
        super();
        this.applicationProvider = applicationProvider;
        System.out.println("Test");
    }

    @Override
    protected Class<? extends Application> getApplicationClass()
            throws ClassNotFoundException {
        return Application.class;
    }

    @Override
    protected Application getNewApplication(HttpServletRequest request)
            throws ServletException {
        return applicationProvider.get();
    }
}

web.xml:

    <filter>
        <filter-name>guiceFilter</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>guiceFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>pl.koziolekweb.vaadin.guice.servlet.VaadinGuiceConfiguration</listener-class>
    </listener>


    <servlet>
        <servlet-name>Vaadin Application Servlet</servlet-name>
        <servlet-class>pl.koziolekweb.vaadin.guice.servlet.GuiceApplicationServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Vaadin Application Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

The problem is that when I run jetty then Guice create instance of servlet (print “Test” in console) but when I try to run application in browser i get NPE and in console “TTest” appear.

So jetty create another instance of servlet that is not managed by guice.

Question is how to configure jetty to use only guice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:33:00+00:00Added an answer on May 20, 2026 at 10:33 am

    You have to create a guice servlet module which extends com.​google.​inject.​servlet.ServletModule (let’s call it FooModule). You define there your bindings and paths to servlets by overriding configureServlets() method.

    Then you must create context listener by extending com.google.inject.servlet.GuiceServletContextListener (let’s call it BarContextListener). There you must implement getInjector() method, with something like that:

    protected Injector getInjector() {
            Injector injector = Guice.createInjector(new FooModule());
            return injector;
        }
    

    Then you remove all servlet mappings from your web.xml, and then put filter:

       <filter>
            <filter-name>guiceFilter</filter-name>
            <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>guiceFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    

    and context listener You created:

    <listener>
            <listener-class>path.to.package.of.context.listener.BarContextListener</listener-class>
        </listener>
    

    By this all Your servlets are managed by Guice and enable dependency injection in server side of Your application. It works for me in Tomcat so it should also work on Jetty. Don’t forget to include guice-servlet-<version>.jar into your classpath. I didn’t use it with Vaadin, but I guess my answer helped You little bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class like so, that I create myself somewhere in my code:
Say I have a ClassWithManyDependencies. I want to write a Guice Provider for this
I would like to achieve something similar to the following in Guice: public MyClass
I'd like to bind a MethodInterceptor in my module's configure() method, like this: public
I'm using Google Guice, Guice servlet, and Jersey. I'd like to find an easy
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
I'm working on Java Swing application with Google Guice as an IOC container. Things
Assume we have a simple @Configuration : @Configuration public class FooBarConfiguration { @Bean public
Say I've got a mock setup like this: JUnit4Mockery context = new JUnit4Mockery(); MyInterface
I'm trying to create a binding of a generic trait using Guice See how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.