2

We used to have code that would bootstrap Google Guice on the startup of our jetty embedded server.

    // add a lifecycle listener to bootstrap injector on startup
    svr.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() {
        @Override
        public void lifeCycleStarted(LifeCycle event) {
            System.out.println("Bootstrapping Guice injector ...");
            Guice.createInjector(new GreeterServletModule(), new GreeterAppModule());
        }
    });

Now when we try to upgrade to Jetty 10 it says addLifeCycleListener no longer exists.

benstpierre
  • 32,833
  • 51
  • 177
  • 288

1 Answers1

0

AbstractLifeCycle.AbstractLifeCycleListener is an EventListener.

use LifeCycle.addEventListener(listener).

Incidentally, the normal way to bootstrap Guice is to extend the com.google.inject.servlet.GuiceServletContextListener and add your extension to the ServletContext listeners?

This is how Google recommends it be done, and is also the way that Google themselves initialize Guice within their own frameworks (like Google App Engine).

Example from Google Cloud Platform Java Samples Project - EchoGuiceListener.java

package com.mycompany;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;

public class GreeterGuiceListener extends GuiceServletContextListener {
  @Override
  protected Injector getInjector() {
    return Guice.createInjector(new GreeterServletModule(), new GreeterAppModule());
  }
}

with ...

ServletContextHandler contextHandler = new ServletContextHandler()
contextHandler.addEventListener(new GreeterGuiceListener());
// ... other init ...
server.start();
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136