2

这是我的 GWT 应用程序中的 web.xml:

<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>

<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>com.myapp.server.guice.ServeModule</param-value>
</context-param>


<listener>
<listener-class>
    com.myapp.server.guice.CustomGuiceResteasyBootstrapServletContextListener
</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>    

我的问题是我如何使它也可用于 GWT-RPC,就像我这样做时一样

服务模块:

@Override
protected void configureServlets() {
    bind(MyService.class).to(MyServiceImpl.class).in(Scopes.SINGLETON);
    serve("/app/myservice").with(MyServiceImpl.class);          
}

对于定义为的 RPC:

@RemoteServiceRelativePath("myservice")
public interface MyService extends RemoteService

当应用程序加载时,它会引发此错误:

[错误] javax.servlet.ServletException:Servlet 必须绑定为单例。Key[type=com.myapp.server.serviceimpl.MyServiceImpl, annotation=[none]] 未绑定在单例范围内。[错误] 在 com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:104) [错误] 在 com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82) [错误] 在 com. google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102) [ERROR] at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172) [ERROR] at org.mortbay.jetty.servlet。 FilterHolder.doStart(FilterHolder.java:97) [ERROR] at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) [ERROR] at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:

  • 我的应用配置可能有什么问题?
  • 我可能错过了哪些设置?
4

3 回答 3

1

将实现 (*Impl) 类绑定到@Singleton范围,或者在ServletModule

bind(MyServiceImpl.class).in(Singleton.class);
serve("/app/myservice").with(MyServiceImpl.class);  

或者通过注释类本身,如xybrek所建议的那样。

于 2013-09-20T14:22:10.080 回答
0

简短的回答是用注释 RPC 服务实现@Singleton

如,com.google.inject.Singleton

于 2013-09-19T14:02:32.167 回答
0

为了回答您的“当我这样做时”,您可能只是使用了错误的单例声明

@Override
public void configureServlets() {

    bind(ImageServlet.class).in(Singleton.class);
    serve("/images").with(ImageServlet.class);
于 2013-09-19T14:03:09.310 回答