我真的不明白为什么errai jax-rs不点火:

用法

@Inject
private Caller<ApiService> myService;

myService.call(new RemoteCallback<MyModel>() {
            @Override
            public void callback(MyModel result) {
                    t.cancel();
                    GWT.log("Response from server: " + result);
                }
            }).create(model);


服务

@Path("api")
public interface ApiService {
    @POST
    @Consumes("application/json")
    @Produces("application/json")
    public MyModel create(MyModel model);
}

public class ApiServiceResource implements ApiService {

    private final InternalService internalService;

    @Inject // Guice
    public ApiServiceResource(InternalService internalService){
        this.internalService = internalService;
    }

    @Override
    public MyModel create(MyModel model) {
        System.out.println("Creating model: " + model.toString());
        return internalService.createModel(model);
    }
}


gwt.xml设置:

   <inherits name="org.jboss.errai.common.ErraiCommon" />
   <inherits name="org.jboss.errai.bus.ErraiBus" />
   <inherits name="org.jboss.errai.ioc.Container" />
   <inherits name="org.jboss.errai.ui.UI" />
   <inherits name="org.jboss.errai.databinding.DataBinding" />
   <inherits name="org.jboss.errai.enterprise.CDI" />
   <inherits name="org.jboss.errai.enterprise.Jaxrs" />
   <inherits name="org.jboss.errai.ui.nav.Navigation"/>


index.html设置:

<script type="text/javascript">erraiBusRemoteCommunicationEnabled = false;</script>


web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

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

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

    <context-param>
        <param-name>resteasy.providers</param-name>
        <param-value>org.jboss.errai.jaxrs.ErraiProvider</param-value>
    </context-param>

    <servlet>
        <servlet-name>ErraiServlet</servlet-name>
        <servlet-class>org.jboss.errai.bus.server.servlet.DefaultBlockingServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>ErraiServlet</servlet-name>
        <url-pattern>*.erraiBus</url-pattern>
    </servlet-mapping>

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

</web-app>


Guice ServeModule:

@Override
protected void configureServlets() {
     bind(ApiService.class).to(ApiServiceResource.class).in(Scopes.SINGLETON)
}

最佳答案

Errai有自己的编组员http://docs.jboss.org/errai/3.0.0.Final/errai/reference/html_single/#sid-5931328

为了使其正常工作,您的POJO必须标记为@Portable注释。
检查您的MyModel类中是否包含它。

没有它,您将得到java.lang.RuntimeException: No marshaller for type: *.MyModel

10-05 18:36