gpt4 book ai didi

java - Errai Jax-RS 不发射

转载 作者:行者123 更新时间:2023-12-02 06:06:10 24 4
gpt4 key购买 nike

我真的不明白为什么 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

关于java - Errai Jax-RS 不发射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22279076/

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