当应用程序作为Eclipse/J2SE运行而不是作为maven jetty:run war运行时调用Restlet createInboundRoot
我有一个简单的Restlet应用程序,在Eclipse中作为J2SE应用程序运行时运行良好,但是当打包为war并使用“mvn jetty:run war”(jetty maven插件)运行时,不会调用application.createInboundRoot方法,因此不会配置路由 相关的错误消息似乎是当应用程序作为Eclipse/J2SE运行而不是作为maven jetty:run war运行时调用Restlet createInboundRoot,eclipse,maven,maven-3,restlet,maven-jetty-plugin,Eclipse,Maven,Maven 3,Restlet,Maven Jetty Plugin,我有一个简单的Restlet应用程序,在Eclipse中作为J2SE应用程序运行时运行良好,但是当打包为war并使用“mvn jetty:run war”(jetty maven插件)运行时,不会调用application.createInboundRoot方法,因此不会配置路由 相关的错误消息似乎是 WARNING: A filter was executed without a next Restlet attached to it. 您可以从控制台输出中看到,在J2SE案例中调用了Mod
WARNING: A filter was executed without a next Restlet attached to it.
您可以从控制台输出中看到,在J2SE案例中调用了ModSpaceRestleApplication.createInboundRoot,而在J2EE案例中未调用该方法。为什么不呢
作为J2SE运行(Eclipse->RunAs->Java应用程序)
通过点击URL进行测试:
http://localhost:8182/modspace/users/fred/entries
返回格式正确的响应,控制台输出为:
In ModspaceRestApplication.ctor
Mar 25, 2014 2:41:15 PM org.restlet.engine.http.connector.HttpServerHelper start
INFO: Starting the internal HTTP server on port 8182
In ModspaceRestApplication.createInboundRoot
使用“mvn jetty:Run war”从命令行以war方式运行
通过点击URL进行测试:
http://localhost:8080/modspace/users/fred/entries
浏览器看到
The server encountered an unexpected condition which prevented it from fulfilling the request
控制台输出为:
2014-03-25 14:42:27.125:INFO:oejs.Server:main: jetty-9.1.0.M0
2014-03-25 14:42:31.507:INFO:oejsh.ContextHandler:main: Started o.e.j.m.p.JettyWebAppContext@6307c51a{/,file:/Users/wilma/eclipse-workspace/modspace-rest/target/modspace-rest-0.0.1-SNAPSHOT/,AVAILABLE}{/Users/wilma/eclipse-workspace/modspace-rest/target/modspace-rest-0.0.1-SNAPSHOT.war}
2014-03-25 14:42:31.509:WARN:oejsh.RequestLogHandler:main: !RequestLog
2014-03-25 14:42:32.004:INFO:oejs.ServerConnector:main: Started ServerConnector@459c745a{HTTP/1.1}{0.0.0.0:8080}
[INFO] Started Jetty Server
In ModspaceRestApplication.ctor
2014-03-25 14:42:50.964:INFO:/:qtp721530251-44: RestletServlet: [Restlet] Attaching application: com.merck.modspace.rest.ModspaceRestletApplication@74e1d431 to URI: /modspace
Mar 25, 2014 2:42:50 PM org.restlet.routing.Filter doHandle
WARNING: A filter was executed without a next Restlet attached to it.
Mar 25, 2014 2:42:51 PM org.restlet.engine.log.LogFilter afterHandle
INFO: 2014-03-25 14:42:50 0:0:0:0:0:0:0:1 - 0:0:0:0:0:0:0:1 8080 GET /modspace/users/fred/entries - 500 365 - 20 http://localhost:8080 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36 -
工具:
Apache Maven 3.0.5
Java version: 1.7.0_51
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="ModspaceWS" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Modspace RESTlet web service</display-name>
<!-- Restlet adapter -->
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<!-- Application class name -->
<param-name>org.restlet.application</param-name>
<param-value>com.merck.modspace.rest.ModspaceRestletApplication</param-value>
</init-param>
</servlet>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/modspace/*</url-pattern>
</servlet-mapping>
</web-app>
现在可以了。我相信问题是由于:
<dependency>
<groupId>org.restlet</groupId>
<artifactId>org.restlet.ext.servlet</artifactId>
<version>2.0-M3</version>
</dependency>
org.restlet
org.restlet.ext.servlet
2.0-M3
应该是:
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet.ext.servlet</artifactId>
<version>2.2.0</version>
</dependency>
org.restlet.jee
org.restlet.ext.servlet
2.2.0
请注意,groupID是错误的,版本是旧的
<dependency>
<groupId>org.restlet</groupId>
<artifactId>org.restlet.ext.servlet</artifactId>
<version>2.0-M3</version>
</dependency>
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet.ext.servlet</artifactId>
<version>2.2.0</version>
</dependency>