Guice ServeContextListener没有启动

时间:2013-04-15 02:05:22

标签: java guice

我正在尝试为@Named中的绑定字符串执行ServeContextListener注入,但是我始终认为String不是绑定异常。所以我猜ServeContextListener没有开始。

这是我的 web.xml 配置:

<!-- GAE-Shiro -->

<context-param>
   <param-name>user-base-url</param-name>
   <param-value>/user/admin</param-value>
</context-param>

<context-param>
    <param-name>static-base-url</param-name>
    <param-value></param-value>
</context-param>

<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>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<listener>
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>org.jboss.errai.ui.demo.server.guice.ServeContextListener</listener-class>
</listener>

<mime-mapping>
    <extension>manifest</extension>
    <mime-type>text/cache-manifest</mime-type>
</mime-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>   

<!-- JBoss Resteasy -->

<context-param>
    <param-name>resteasy.guice.modules</param-name>
    <param-value>org.jboss.errai.ui.demo.server.guice.ServeModule</param-value>
</context-param>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener
    </listener-class>
</listener>

<context-param>  
    <param-name>resteasy.servlet.mapping.prefix</param-name>  
    <param-value>/</param-value>  
</context-param>

<servlet>
    <servlet-name>Resteasy</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping> 

实际绑定位于ServeLogic

@Override
protected Injector getInjector() {
    return Guice.createInjector(new ServeLogic(userBaseUrl, staticBaseUrl), new ServeModule(userBaseUrl));
}

唯一受约束的是resteasy.guice.modules

中的那些
org.jboss.errai.ui.demo.server.guice.ServeModule

为什么?

1 个答案:

答案 0 :(得分:0)

我已经通过以下方式解决了这个问题:

  • 扩展GuiceResteasyBootstrapServletContextListener并将ServeContextListener与它结合使用。
  • 这样app只有一个Context Listener,它是GuiceResteasyBootstrapServletContextListener

因此我只有这个听众:

<listener>
    <listener-class>
        org.jboss.errai.ui.demo.server.guice.CustomGuiceResteasyBootstrapServletContextListener
    </listener-class>
</listener>