我搜索并尝试了几个小时来解决这个问题,遗憾的是没有成功。
我正在使用Java 1.6,RESTEasy 2.2.1.GA和Jetty Embedded Server来设置Web服务。 最初我复制了一个现有的工作项目来设置这个。不知何故,原始项目有效,我调整后的副本无效。
启动嵌入式服务器后,我遇到以下异常:
以下是控制台所说的内容:
2011-10-27 09:22:51.113::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2011-10-27 09:22:51.141::INFO: jetty-6.0.2
2011-10-27 09:22:51.352::WARN: failed Resteasy
javax.servlet.UnavailableException: org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:78)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:229)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:574)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:128)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1219)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:421)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:119)
at org.mortbay.jetty.Server.doStart(Server.java:228)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at com.xtag.locationadapter.webui.EmbeddedServer.main(EmbeddedServer.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
2011-10-27 09:22:51.398::WARN: Failed startup of context org.mortbay.jetty.webapp.WebAppContext@1c5d9084{/admin,file:/Users/workspace/LocationAdapter/webui/target/classes/com/company/locationadapter/webui/webapp/}
javax.servlet.UnavailableException: org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
at org.mortbay.jetty.servlet.Holder.doStart(Holder.java:78)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:229)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:574)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:128)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1219)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:421)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:119)
at org.mortbay.jetty.Server.doStart(Server.java:228)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
at com.xtag.locationadapter.webui.EmbeddedServer.main(EmbeddedServer.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
2011-10-27 09:22:51.400::INFO: Started SocketConnector @ 0.0.0.0:8088
这是我的项目结构。请忽略webui名称不适合此文件夹内容的事实。:
LocationAdapter
- .idea
- .settings
- bin
- webui
|- src
|- main
|- java
|- com.company.locationadapter.communication.rest
|- ResteasyApplication.java
|- com.company.locationadapter.communication.restservices
|- LocationResource.java
|- LocationResourceImpl.java
|- com.company.locationadapter.service
|- LocationService.java
|- LocationServiceImpl.java
|- com.company.locationadapter.webui
|- EmbeddedServer.java
|- resources
|- com.company.locationadapter.webui.webapp
|- dummy.html
|- com.company.locationadapter.webui.webapp.WEB-INF
|- web.xml
我的ResteasyApplication类:
public class ResteasyApplication extends Application {
@Override
public Set<Object> getSingletons() {
Set<Object> set = new HashSet<Object>();
set.add(new LocationResourceImpl());
return set;
}
@Override
public Set<Class<?>> getClasses() {
return super.getClasses();
}
}
我的EmbeddedServer类:
public class EmbeddedServer {
private static final String WEBAPP = "com/company/locationadapter/webui/webapp";
private static final String CONTEXT_PATH = "/admin";
public static void main(String[] args) throws Exception {
addSystemProperties();
final Server server = new Server(8088);
final URL warUrl = EmbeddedServer.class.getClassLoader().getResource(WEBAPP);
final String warUrlString = warUrl.toExternalForm();
server.setHandler(new WebAppContext(warUrlString, CONTEXT_PATH));
server.start();
}
protected static void addSystemProperties() {
try {
Properties properties = new Properties(System.getProperties());
String path = System.getProperty("user.properties");
properties.load(new FileInputStream(new File(path)));
System.setProperties(properties);
} catch (IOException e) {
e.printStackTrace();
}
}
}
用于配置RESTEasy的web.xml:
<web-app>
<display-name>LocationAdapter</display-name>
<description>Company</description>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/locationadapter</param-value>
</context-param>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.company.locationadapter.communication.rest.ResteasyApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
如果有人对此例外有任何想法或解决方案,我将非常感激。 如果您需要进一步的信息,请告诉我。
提前致谢!
答案 0 :(得分:2)
问题解决后,异常是由POM.xml中的条目引起的,其中工件“resteasy-jaxb-provider”的范围设置为