1

我正在尝试@Named为 中的绑定 String 进行注入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

这是为什么?

4

1 回答 1

0

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

  • 扩展 GuiceResteasyBootstrapServletContextListener 并将 ServeContextListener 结合到它。
  • 这样,应用程序只有一个上下文侦听器,即 GuiceResteasyBootstrapServletContextListener

因此我只有这个听众:

<listener>
    <listener-class>
        org.jboss.errai.ui.demo.server.guice.CustomGuiceResteasyBootstrapServletContextListener
    </listener-class>
</listener>
于 2013-04-16T00:45:50.560 回答