java - Rest Web 服务 404 错误 - JBoss Eclipse
问题描述
大家好,我有一个问题,我无法在 JBOSS 7.0.1 服务器上部署 restful 服务,它显示为已部署,但问题是当我在服务中通过邮寄尝试时,我收到 404 错误....我没有不知道在这种情况下该怎么做,与同一台服务器上的其他 Web 项目我没有问题。
这是一个从 SVN 存储库导入的项目。
我发帖的链接是 http://localhost:8080/Project-WAR/ServiceExample/test
我有树项目:
- 项目-EAR
- 项目-EJB
- 项目-WAR
服务器日志
14:45:42,850 INFORMACIÓN [org.jboss.modules] JBoss Modules version 1.1.5.GA
14:45:43,131 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
14:45:43,293 INFO [org.jboss.as] JBAS015899: JBoss AS 7.1.0.Final "Thunder" starting
14:45:44,258 INFO [org.xnio] XNIO Version 3.0.3.GA
14:45:44,258 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
14:45:44,267 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
14:45:44,282 INFO [org.jboss.remoting] JBoss Remoting version 3.2.2.GA
14:45:44,298 INFO [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
14:45:44,313 INFO [org.jboss.as.configadmin] (ServerService Thread Pool -- 26) JBAS016200: Activating ConfigAdmin Subsystem
14:45:44,345 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
14:45:44,376 INFO [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
14:45:44,376 INFO [org.jboss.as.security] (MSC service thread 1-3) JBAS013100: Current PicketBox version=4.0.6.final
14:45:44,392 INFO [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
14:45:44,413 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
14:45:44,425 INFO [org.jboss.as.connector] (MSC service thread 1-4) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.7.Final)
14:45:44,431 INFO [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service
14:45:44,439 INFO [org.jboss.as.mail.extension] (MSC service thread 1-4) JBAS015400: Bound mail session [java:jboss/mail/Default]
14:45:44,558 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
14:45:44,766 INFO [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-4) JBoss Web Services - Stack CXF Server 4.0.1.GA
14:45:44,839 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class com.microsoft.sqlserver.jdbc.SQLServerDriver (version 4.0)
14:45:44,864 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
14:45:45,232 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-1) Arrancando Coyote HTTP/1.1 en puerto http--0.0.0.0-8080
14:45:45,232 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-2) Arrancando Coyote HTTP/1.1 en puerto http--0.0.0.0-8443
14:45:45,393 INFO [org.jboss.as.remoting] (MSC service thread 1-6) JBAS017100: Listening on /0.0.0.0:4447
14:45:45,395 INFO [org.jboss.as.remoting] (MSC service thread 1-5) JBAS017100: Listening on localhost/127.0.0.1:9999
14:45:45,397 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-2) JBAS015012: Started FileSystemDeploymentService for directory C:\jboss-as-7.1.0.Final\standalone\deployments
14:45:45,401 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015014: Re-attempting failed deployment Project-EAR.ear
14:45:45,423 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found Project-EAR.ear in deployment directory. To trigger deployment create a file called Project-EAR.ear.dodeploy
14:45:45,626 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "Project-EAR.ear"
14:46:03,066 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry jaxb-api.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,068 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry activation.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,071 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry jsr173_1.0_api.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,074 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry jaxb1-impl.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,077 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry jaxb-api.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-xjc-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,079 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry jaxb-impl.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-xjc-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,082 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry jsr173_1.0_api.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-xjc-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,085 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry activation.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/jaxb-xjc-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,089 WARN [org.jboss.as.server.deployment] (MSC service thread 1-3) Class Path entry activation.jar in "/C:/jboss-as-7.1.0.Final/standalone/deployments/Project-EAR.ear/mail-1.4.jar" does not point to a valid jar for a Class-Path reference.
14:46:03,097 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "Project-WAR.war"
14:46:03,381 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016002: Processing weld deployment Project-EAR.ear
14:46:03,434 INFO [org.jboss.weld.deployer] (MSC service thread 1-5) JBAS016002: Processing weld deployment Project-WAR.war
14:46:03,450 INFO [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016005: Starting Services for CDI deployment: Project-EAR.ear
14:46:03,483 INFO [org.jboss.weld.Version] (MSC service thread 1-4) WELD-000900 1.1.5 (AS71)
14:46:03,516 INFO [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016008: Starting weld service for deployment Project-EAR.ear
14:46:03,990 INFO [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /Project-WAR
14:46:03,992 INFO [org.jboss.as] (MSC service thread 1-4) JBAS015874: JBoss AS 7.1.0.Final "Thunder" started in 21819ms - Started 238 of 327 services (76 services are passive or on-demand)
14:46:04,035 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "Project-EAR.ear"
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Restful Web Application</display-name>
</web-app>
应用配置.java
package com.services.rest;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<Class<?>>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(ServiceExample.class);
}
}
解决方案
您必须在 web.xml 中添加以下内容。看起来 web.xml 有点空。它应该看起来像这样。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.services.rest</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>
</web-app>
你还应该有一个 Resource 类,它应该至少有一个像这样的端点。我在下面提供一个例子。
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() {
return "Hello World";
}
推荐阅读
- netlogo - How can I solve the error (you can not use my_ area in a patch context, it is a turtle-only)?
- django - Django,用公共部分分开设置文件
- apache-kafka - Kafka - 不同的配置设置
- python - 读取多个数据集
- amazon-web-services - S3 如何使公共 URL 唯一
- python - 如何将文本变成字典列表
- python - 尝试绘图时在赋值之前引用的局部变量
- holtwinters - 解释 HoltWinters 返回的拟合值
- multithreading - Java 多客户端 - 服务器 javafx
- java - 我完美运行的 Java 代码在 IntelliJ IDEA 中引发异常