Java的球衣休息:未找到提供者类。 (404错误访问URL时) [英] Java Jersey Rest : No provider classes found. (404 error when accessing URL)
问题描述
编辑:我没有意识到,所有的请求都首先进入阿帕奇,然后重定向到Tomcat中。我在 apache2.conf
文件添加一个新的重定向。详情请参阅接受的答案。
I hadn't realized that all request were first going into "Apache" and then were redirected to Tomcat. I added a new redirection in the
apache2.conf
file. See the accepted answer for details.
我有完全相同的问题,因为这个问题。
<一href=\"http://stackoverflow.com/questions/6111074/jersey-rest-the-resourceconfig-instance-does-not-contain-any-root-resource-classe\">Jersey其余ResourceConfig实例不包含任何根资源类
然而,用户永远不会回答了这个问题。
I am having the exact same problem as this question. Jersey REST The ResourceConfig instance does not contain any root resource classes However the user never answered the question.
我使用Tomcat,没有行家。我跟着这个教程。
<一href=\"http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/index.html\">http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/index.html
I am using Tomcat, without maven. I followed this tutorial. http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/index.html
我做了修改web.xml中根据文章结果
即新的servlet和servlet映射与正确的包名称创建。
I made changes to web.xml as per the article
i.e the new servlet and servlet mapping was created with the correct package name.
<servlet>
<servlet-name>Jersey REST Service</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>sample.hello.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
我已经部署了以下jar文件到Tomcat
I have deployed the following jars to tomcat
asm.jar
jersey-server.jar
jersey-core.jar
jsr311.jar
Tomcat启动日志有以下例外情况。
The tomcat startup log has the following exceptions.
com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
sample.hello.resources
com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class sample.hello.resources.HelloResource
com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
在我访问的网址,我收到了404。
的http://本地主机:8080 /新泽西/ REST /你好
When I access the URL I get a 404. http://localhost:8080/Jersey/rest/hello
在code:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class HelloResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() {
return "Hello Jersey";
}
}
我看不出在日志中其他异常
I do not see any other exceptions in the logs
推荐答案
这个问题就解决了如下。我的本地主机已经创建了阿帕奇网络服务器会被重定向到Tomcat的所有请求。由于泽西是用一个新的servlet,我不得不创建一个单独的重定向为这个servlet明确。
This issue was resolved as follows. My localhost has been setup with "Apache" webserver which redirects all requests to Tomcat. Since "Jersey" is using a new servlet, I had to create a separate redirect for this servlet specifically.
在Linux的
/etc/apache2/apache2.conf
地址:
JkMount /rest/* ajp13_worker
这篇关于Java的球衣休息:未找到提供者类。 (404错误访问URL时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!