gpt4 book ai didi

java - Guice ServeContextListener 没有启动

转载 作者:行者123 更新时间:2023-12-01 04:44:58 25 4
gpt4 key购买 nike

我正在尝试为 ServeContextListener 中的绑定(bind)字符串进行 @Named 注入(inject),但是我总是得到该字符串未绑定(bind)的异常。所以我猜 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>

实际绑定(bind)位于ServeLogic中:

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

唯一被绑定(bind)的是resteasy.guice.modules中的那些:

org.jboss.errai.ui.demo.server.guice.ServeModule

这是为什么?

最佳答案

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

  • 扩展 GuiceResteasyBootstrapServletContextListener 并将 ServeContextListener 与其结合。
  • 这样应用程序就只有一个上下文监听器,即 GuiceResteasyBootstrapServletContextListener

因此我只有这个监听器:

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

关于java - Guice ServeContextListener 没有启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16006617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com