提问者:小点点

让GWT RPC与Guice配合使用


这就是网络。我的GWT应用程序中的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 . servlet异常:servlet必须绑定为singletons。key[type = com . myapp . server . service impl . myserviceimpl,annotation=[none]]未在单独范围内绑定。[错误]在com . Google . inject . servlet . servlet definition . init(servlet definition . Java:104)[错误]在com . Google . inject . servlet . managedservletpipeline . init(managedservletpipeline . Java:82)[错误]在com . Google . inject . servlet . guice filter . init(guice filter . Java:172)[错误

  • 我的应用程序配置可能出现什么问题?
  • 我能错过什么设置?

共3个答案

匿名用户

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

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

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

匿名用户

简单的回答是用< code>@Singleton注释RPC服务实现

如,com.google.inject.Singleton

匿名用户

为了回答你的“也当我这样做的时候”,你可能只是使用了错误的辛格尔顿声明

@Override
public void configureServlets() {

    bind(ImageServlet.class).in(Singleton.class);
    serve("/images").with(ImageServlet.class);