对于文本墙提前抱歉,但我想要彻底,以免浪费你的时间,善良的StackOverflow-ers。 : - )
我已经在Tomcat 7中成功部署并测试了RESTful Web服务作为war文件,因为JBoss使用Tomcat作为组件,我(错误地)认为部署就像将war文件放入JBoss 6.1一样简单server / default / deploy目录,不!起初我得到一个错误,只允许一个JAX-RS应用程序类,这可以通过从Jboss中的deployers / dir中删除resteasy.deployer(所有,默认和标准服务器只是为了彻底)来轻松解决。
现在关键是我在Jboss启动期间收到以下消息:
10:38:07,431 INFO [PackagesResourceConfig] Scanning for root resource and provider classes in the packages:
net.ussouth.incomm.SPIL.resource
10:38:07,486 INFO [WebApplicationImpl] Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
10:38:07,718 SEVERE [RootResourceUriRules] The ResourceConfig instance does not contain any root resource classes.
10:38:07,719 ERROR [[/SPIL]] StandardWrapper.Throwable: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99) [:1.11]
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298) [:1.11]
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169) [:1.11]
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775) [:1.11]
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771) [:1.11]
这是位于WEB-INF / classes目录下的Resource类:
package net.ussouth.incomm.SPIL.resource;
import javax.ws.rs.Path;
import javax.ws.rs.POST;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.Produces;
import javax.ws.rs.FormParam;
import org.apache.log4j.Logger;
@Path("/message")
public class MessageResource {
private static Logger log = Logger.getLogger(MessageResource.class);
@POST
@Path("/Search")
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public String search(@FormParam("message") String _msgToProvider, @FormParam("provider") String _provData) {
log.info("MesageResource.search method called");
String outVal = null;
try{
ProviderHandler hnd = new ProviderHandler();
outVal = hnd.getOffers(_msgToProvider);
} catch(JAXBException ex) {
...
} catch (SearchException ex) {
...
}
return outVal;
}
}
这是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_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>Spil</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SpilMessageService</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>net.ussouth.incomm.SPIL.resource</param-value>
</init-param>
<init-param>
<param-name>log4j-properties-location</param-name>
<param-value>classes/log4j.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpilMessageService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
最后,为了更好的衡量,这里是jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
<context-root>SPIL</context-root>
</jboss-web>
感谢您的帮助。我花了1.5天时间研究并将头撞在墙上。
答案 0 :(得分:4)
您需要的只是使用便携式JAX-RS部署方法,如here所述。不使用包扫描,而是使用javax.ws.rs.core.Application
的实现强制手动扫描import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
// register resources
classes.add(MessageResource.class);
return classes;
}
}
然后,更新您的web.xml以使用它。请记住禁用resteasy扫描,如下所示。
<?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_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5">
<display-name>Spil</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SpilMessageService</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>net.ussouth.incomm.SPIL.resource.MyApplication</param-value>
</init-param>
<init-param>
<param-name>log4j-properties-location</param-name>
<param-value>classes/log4j.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>false</param-value>
</context-param>
<servlet-mapping>
<servlet-name>SpilMessageService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
答案 1 :(得分:0)
的Orf
我遇到了同样的问题(Jersey 1.11 + tomcat 7)。但是在我改为tomcat 6之后,球衣工作了!
我不知道为什么,但我建议你改变并尝试。