我想調用restful webservice使用客戶端web應用程序(簡單的客戶端請求從JSF MB)。我需要爲webservice創建一個接口,然後調用其中的方法。但是,如果我在接口使用@Path,它會給出一個錯誤 - 在Jboss部署期間找不到公共構造函數。但是如果我給實施課的@Path。它正在調用服務並且工作正常。我需要在Rest客戶端和Restful webservice impl類之間有一個Java接口。誰能幫忙?我們可以有Rest接口嗎?寧靜的webservice公共構造函數未找到
客戶端:
ClientRequest request = new ClientRequest("localhost:8080/RESTfulExample/json/...../");
ClientResponse<String> response = request.get(String.class);
RestInterface:
package com.nee.interfaces;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
@Path("/OrderManagementService")
public interface OrderManagementServiceInterface {
@GET
@Path("/GetListOfOrders")
void getListOfOrders();
}
IMPL:
package com.nee.implementations;
import com.nee.interfaces.OrderManagementServiceInterface;
public class OrderManagementServiceImpl implements OrderManagementServiceInterface {
public void getListOfOrders() {
System.out.println("am here");
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>
com.nee.interfaces.OrderManagementServiceInterface
</param-value>
</context-param>
<!-- this has to match with resteasy-servlet url-pattern -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<!-- to return data according to extension -->
<context-param>
<param-name>resteasy.media.type.mappings</param-name>
<param-value>json : application/json, xml : application/xml</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
日誌:
[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/web]]
(MSC service thread 1-2) Exception sending context initialized event to listener instance of class
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.RuntimeException: Unable to find a public constructor for class com.seagate.interfaces.OrderManagementServiceInterface
at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.registered(POJOResourceFactory.java:35) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:120) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:106) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:83) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:72) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:383) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:225) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28) [resteasy-jaxrs-2.3.3.Final-redhat-1.jar:2.3.3.Final-redhat-1]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.16.Final-redhat-1.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.16.Final-redhat-1.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)[rt.jar:1.7.0_09]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_09]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_09]
發佈您的代碼。如果您使用的是接口,則應該在其上定義所有JAX-RS註釋。 – Perception 2013-02-21 01:05:13
請用格式良好的代碼更新您的文章。 – jdevelop 2013-02-21 01:19:02
您的界面代碼不可編譯。我們也需要你的實現代碼。 – Perception 2013-02-21 01:29:45