= Google App EngineでGuiceを使う = [[http://code.google.com/intl/ja/appengine/|Google App Engine]]でモジュラーなアプリケーションを作成するのにGuiceを使うことができる。 == Supported Builds == Google App Engine support requires Guice 2 (with or without AOP), plus the guice-servlet extension. Setup Servlet and Filter Registration Configure servlets and filters by subclassing ServletModule: {{{ package com.mycompany.myproject; import com.google.inject.servlet.ServletModule; class MyServletModule extends ServletModule { @Override protected void configureServlets() { serve("/*").with(MyServlet.class); } } }}} Injector Creation Construct your Guice injector in the getInjector() method of a class that extends GuiceServletContextListener. Be sure to include your application's servlet module in the list of modules. {{{ package com.mycompany.myproject; import com.google.inject.servlet.ServletModule; import com.google.inject.servlet.GuiceServletContextListener; import com.google.inject.Guice; import com.google.inject.Injector; public class MyGuiceServletContextListener extends GuiceServletContextListener { @Override protected Injector getInjector() { return Guice.createInjector( new MyServletModule(), new BusinessLogicModule()); } } }}} Web.xml Configuration You must register both the GuiceFilter and your subclass of GuiceServletContextListener in your application's web.xml file. All other servlets and filters may be configured in your servlet module. {{{ My Project guiceFilter com.google.inject.servlet.GuiceFilter guiceFilter /* com.mycompany.myproject.MyGuiceServletContextListener }}} WAR Layout Ensure the AOP alliance, Guice, and Guice servlet jars are in the WEB-INF/lib directory of your .war file (or www directory): {{{ www/ WEB-INF/ lib/ aopalliance.jar guice-servlet-snapshot.jar guice-snapshot.jar ... classes/ ... appengine-web.xml web.xml }}}