我创建了一个maven项目,其原型为maven-archetype-webapp,然后将我的应用程序作为休息webservice公开,我正在使用RestEasy,但是在实现其余应用程序后,我无法访问由我创建的URL 。 请指导我做错了什么。感谢您阅读此问题。
我的UserManagementController如下:
package com.restimplement.btl.pl.controller;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import com.restimplement.btl.pl.dao.UserDao;
@Path(value="/UserManagement")
public class UserManagementController {
@GET
@Path("/{pathParameter}")
public Response getAllUsers( @PathParam("pathParameter") String pathParameter,
@DefaultValue("Nothing to say") @QueryParam("queryParameter") String queryParameter)
{
UserDao userdao = new UserDao();
System.out.println("able to visit user add");
String response = "details from: "+userdao.findObject();
return Response.status(200).entity(response).build();
}
}
我的MyRestWS.java如下:
package com.restimplement.btl.pl.controller;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class MyRestWS extends Application{
private Set<Object> singletons = new HashSet<Object>();
public MyRestWS() {
singletons.add(new UserManagementController());
}
}
我的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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>BTL_PL</display-name>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/btlservice/*</url-pattern>
</servlet-mapping>
<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/btlservice</param-value>
</context-param>
<servlet>
<servlet-name>resteasy-servlet</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.restimplement.btl.pl.controller.MyRestWS</param-value>
</init-param>
</servlet>
</web-app>
应用程序已在JBoss-wildfly 8上成功部署,但在访问URL时http://localhost:8080/BTL_PL/btlservice/UserManagement/getUser;我在jboss控制台上遇到错误:
14:19:33,240 WARN [org.jboss.resteasy.core.ExceptionHandler] (default task-10)
failed to execute: javax.ws.rs.NotFoundException: Could not find resource for fu
ll path: http://localhost:8080/BTL_PL/btlservice/UserManagement/getUser
at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) [
resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.ja
va:48) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(Res
ourceMethodRegistry.java:444) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousD
ispatcher.java:234) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispa
tcher.java:171) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.
service(ServletContainerDispatcher.java:220) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.servi
ce(HttpServletDispatcher.java:56) [resteasy-jaxrs-3.0.6.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.servi
ce(HttpServletDispatcher.java:51) [resteasy-jaxrs-3.0.6.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-s
ervlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHand
ler.java:85) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.hand
leRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.0.Final.jar:
1.0.0.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(
ServletDispatchingHandler.java:36) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final
]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHan
dler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateH
andler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandle
r.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0
.0.Final.jar:1.0.0.Final]
at io.undertow.security.handlers.AuthenticationCallHandler.handleRequest
(AuthenticationCallHandler.java:52) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRe
quest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.0.Final.jar:1.0
.0.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstrain
tHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [underto
w-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandl
er.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.
0.0.Final.jar:1.0.0.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(Se
curityInitialHandler.java:76) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateH
andler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.han
dleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateH
andler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateH
andler.java:25) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest
(ServletInitialHandler.java:240) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(Se
rvletInitialHandler.java:227) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(Servlet
InitialHandler.java:73) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(Se
rvletInitialHandler.java:146) [undertow-servlet-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:168)
[undertow-core-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:6
87) [undertow-core-1.0.0.Final.jar:1.0.0.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1145) [rt.jar:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:615) [rt.jar:1.7.0_79]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]
如果我需要在查询中添加其他内容以获取更多信息,请告知我们。此外,如果我正在尝试访问错误的网址。
答案 0 :(得分:2)
web.xml
在Servlet 3.x环境(如WildFly 8.x)中,web.xml
部署描述符不是必需的,您可能不需要在简单的应用程序中使用它。
您可以删除它并将maven-war-plugin
配置为通过在web.xml
文件中将failOnMissingWebXml
配置属性设置为false
来忽略丢失的pom.xml
文件:< / p>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
...
</plugins>
Application
子类将您的Application
子类更改为:
@ApplicationPath("btlservice")
public class MyRestWS extends Application {
@Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> set = new HashSet<Class<?>>();
set.add(UserManagementController.class);
return set;
}
}
getClasses()
方法返回一组根资源,提供者和feature类。资源类实例的默认生命周期是每个请求。提供者的默认生命周期(直接注册或通过功能注册)是单身。
@ApplicationPath
注释可用于注释自定义Application
子类,并为应用程序中配置的所有JAX-RS资源定义基本应用程序URI。有了它,您不需要在web.xml
部署描述符中声明servlet。
有关Application
课程的详细信息,此answer可以提供深刻见解。
最后,请求您的端点应在以下网址中提供:
http://[server]:[port]/[context]/btlservice/UserManagement/[path-parameter]