我创建了一个最近使用 wicket REST functionality 升级的 Wicket 应用程序.在开发它并通过 Jetty 运行时,我能够正确地将消息发布到 REST 服务。但是,当它部署到 tomcat 时,转到 REST URL 会出现 404 错误和“请求的资源不可用”响应。
Pom 条目: wicketstuff-annotation、wicketstuff-restannotations、wicketstuff-restannotations-json(所有 jar/compile,版本与 wicket 版本 6.24.0 相同)
rest类中的代码
public class Webhook extends AbstractRestResource<JsonWebSerialDeserial> {
@MethodMapping(value="/notification", httpMethod=HttpMethod.POST, consumes= RestMimeTypes.APPLICATION_JSON, produces = RestMimeTypes.TEXT_PLAIN)
public String notification( @RequestBody Notification data ) {
// do some things
return "received successfully";
}
@Override
public String getMountPath() {
return "/emailcampaign/webhook";
}
}
REST 类在 WicketApplication 中初始化:
public void init() {
final Webhook hook = new Webhook();
mountResource( hook.getMountPath(), new ResourceReference( hook.getClass().getSimpleName() ) {
private static final long serialVersionUID = 1L;
public IResource getResource() {
return hook;
}
});
}
tomcat localhost_access_logs 有这个:
`XX.XX.XX.XX - - [01/Feb/2018:06:46:10 +0000] "POST /emailcampaign/webhook/notification HTTP/1.1" 404 1041
系统启动正确,所以我在部署时似乎没有丢失任何 jar 文件,所以我不知所措。有人可以帮忙吗?
Tomcat 7.0.67、Jetty 7.6.3、Wicket 6.24、Spring 4.1.4
编辑:这是 web.xml 的内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_2_5.xsd"
version="2.5">
<display-name>system-ui</display-name>
<context-param>
<param-name>configuration</param-name>
<param-value>deployment</param-value>
</context-param>
<filter>
<filter-name>wicket.system-ui</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.sw.system.ui.WicketApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.system-ui</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
最佳答案
....aa,这是菜鸟的疏忽。
在我的开发机器上,jetty 上应用程序的路径是 http://localhost:8080 .在部署机器上,它是 http://[server_name]/theapp .所以我将客户端 REST URL 设置为指向 http://[server_name]/theapp/emailcampaign/webhook/notification (即添加 theapp 子路径)并且成功了!
Doh 但希望它能帮助其他人。
关于java - Wicket REST 功能适用于 Jetty 但不适用于 Tomcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48561049/