- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
所以....
我已经能够配置 RestEasy 服务并让它在我的 Windows 8 上的 Eclipse 中工作但是当我将它部署在安装在 Ubuntu 上的 Tomcat 7 上时它不起作用!
当我在 Eclipse 上启动我的 tomcat 时,我收到消息:
INFO: Starting Servlet Engine: Apache Tomcat/7.0.29
nov. 12, 2014 4:00:06 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
nov. 12, 2014 4:00:07 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'MessageBrokerServlet'
[INFO ] 2014-11-12 16:00:08,001 org.jboss.resteasy.spi.ResteasyDeployment - Deploying javax.ws.rs.core.Application: class fr.mycompany.myproject.MarkersApplication
但是这最后一行不存在于 ubuntu 上的 tomcat 服务器的日志中=> 因此,当我调用我的 Rest 服务(通过 javascript/jsapi)时,我收到了这条消息:
GRAVE: "Servlet.service()" pour la servlet RESTEasy JSAPI a généré une exception
java.lang.NullPointerException
at org.jboss.resteasy.jsapi.JSAPIWriter.generateEtag(JSAPIWriter.java:111)
at org.jboss.resteasy.jsapi.JSAPIWriter.writeJavaScript(JSAPIWriter.java:36)
at org.jboss.resteasy.jsapi.JSAPIServlet.service(JSAPIServlet.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
null(我想)是 generateEtag() 方法的 serviceRegistries
,它在 Eclipse Tomcat 中启动时用我的 RestService 填充。
我不知道为什么 ResteasyServletInitializer 会启动/初始化,所以如果有人遇到这种情况(以及解决方案 ^^),请帮助我 T_T
这是我使用的配置:
申请声明:
@ApplicationPath("/resteasy")
public class MarkersApplication extends Application {
}
服务:
@Path("/markersRest")
public class MarkersRest {
@Context
private ServletContext context;
private DataService getService() {
return WebApplicationContextUtils.getWebApplicationContext(context).getBean(DataService.class);
}
@POST
@Produces(MediaType.TEXT_PLAIN)
public Response getMarkers(@QueryParam("keyCache") String keyCache) {
String markers = getService().getCachedMarkers(keyCache);
return Response.ok().entity(markers).build();
}
}
web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="true">
<display-name>MyProject</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/spring-config.xml</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/resteasy</param-value>
</context-param>
<!-- ************************ -->
<!-- ******* LISTENERS ****** -->
<!-- ************************ -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>
<!-- ************************ -->
<!-- ******* SERVLETS ******* -->
<!-- ************************ -->
<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/spring-flex-config.xml</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MessageBrokerServlet</servlet-name>
<url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RESTEasy JSAPI</servlet-name>
<servlet-class>org.jboss.resteasy.jsapi.JSAPIServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy JSAPI</servlet-name>
<url-pattern>/rest-js</url-pattern>
</servlet-mapping>
</web-app>
pom.xml :
...
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.0.9.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jsapi</artifactId>
<version>3.0.9.Final</version>
</dependency>
...
和文件 /WEB-INF/services/javax.servlet.ServletContainerInitializer
内容为 org.jboss.resteasy.plugins.servlet.ResteasyServletInitializer
最佳答案
好的,我找到了\o/,对于那些遇到这个问题的人,这里是解决方案:
在 web.xml 中添加 servlet 声明:
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>fr.mycompany.myproject.MarkersApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/resteasy/*</url-pattern>
</servlet-mapping>
并覆盖您的 SubApplication 上的方法:
@ApplicationPath("/resteasy")
public class MarkersApplication extends Application {
private static final Set<Object> singletons = new HashSet<Object>();
public MarkersApplication() {
singletons.add(new MarkersRest());
}
@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
return set;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
关于java - RestEasy - ResteasyServletInitializer 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26892417/
所以.... 我已经能够配置 RestEasy 服务并让它在我的 Windows 8 上的 Eclipse 中工作但是当我将它部署在安装在 Ubuntu 上的 Tomcat 7 上时它不起作用! 当我
我是一名优秀的程序员,十分优秀!