2017-07-14 34 views
0

嗨,我正在開發一個RestJet與IntelliJ下面the official doc如何使用wildfly訪問我的REST資源?

但是我在訪問資源時遇到404未找到錯誤...我仍然可以訪問index.jsp頁面。我遵循de doc的每一步,但我使用Wildfly而不是Glassfish。

以下是資源:

@Path("devices") 
public class DevicesResource { 

    @GET 
    @Produces(MediaType.TEXT_PLAIN) 
    public String getAllDevices() { 
     return "Hello world from thingsplay."; 
    } 

} 

這裏是應用程序子類:

@ApplicationPath("/api/v2.0") 
public class ApplicationConfig extends Application { 

    @Override 
    public Set<Class<?>> getClasses() { 
     Set<Class<?>> resources = new HashSet<>(); 
     addResourceClasses(resources); 
     return resources; 
    } 

    public void addResourceClasses(Set<Class<?>> resources) { 
     resources.add(be.thingsplay.resources.DevicesResource.class); 
    } 

} 

所以,當我訪問http://localhost:8080/api/v2.0我得到的索引頁,但是當我試圖訪問http://localhost:8080/api/v2.0/devices我得到一個404未找到錯誤。

當我看着神器時,我注意到澤西圖書館沒有被列入戰爭。但是當我嘗試將它添加到戰爭中時,我會在嘗試部署應用程序時遇到異常。

enter image description here

例外,我得到:

14:57:23,799 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "apirest_war_exploded.war" (runtime-name: "apirest_war_exploded.war") 
14:57:24,147 WARN [org.jboss.weld.deployer] (MSC service thread 1-2) WFLYWELD0013: Deployment deployment "apirest_war_exploded.war" contains CDI annotations but no bean archive was not found. (No beans.xml nor class with bean defining annotations) 
14:57:24,178 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 89) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
    at org.jboss.threads.JBossThread.run(JBossThread.java:320) 
Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    at org.glassfish.jersey.internal.ServiceFinder.<clinit>(ServiceFinder.java:165) 
    at org.glassfish.jersey.servlet.internal.ServletContainerProviderFactory.getAllServletContainerProviders(ServletContainerProviderFactory.java:66) 
    at org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer.onStartup(JerseyServletContainerInitializer.java:132) 
    at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:186) 
    at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:171) 
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42) 
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43) 
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) 
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) 
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) 
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) 
    at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44) 
    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:234) 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100) 
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82) 
    ... 6 more 
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function from [Module "deployment.apirest_war_exploded.war:main" from Service Module Loader] 
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351) 
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93) 
    ... 21 more 

14:57:24,182 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 20) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "apirest_war_exploded.war")]) - failure description: { 
    "WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./apirest_war_exploded" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function from [Module \"deployment.apirest_war_exploded.war:main\" from Service Module Loader]"}, 
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./apirest_war_exploded"], 
    "WFLYCTL0180: Services with missing/unavailable dependencies" => undefined 
} 
14:57:24,183 ERROR [org.jboss.as.server] (management-handler-thread - 20) WFLYSRV0021: Deploy of deployment "apirest_war_exploded.war" was rolled back with the following failure message: 
{ 
    "WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./apirest_war_exploded" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function from [Module \"deployment.apirest_war_exploded.war:main\" from Service Module Loader]"}, 
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./apirest_war_exploded"], 
    "WFLYCTL0180: Services with missing/unavailable dependencies" => undefined 
} 
14:57:24,207 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment apirest_war_exploded.war (runtime-name: apirest_war_exploded.war) in 23ms 
14:57:24,208 INFO [org.jboss.as.controller] (management-handler-thread - 20) WFLYCTL0183: Service status report 
WFLYCTL0184: New missing/unsatisfied dependencies: 
     service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded (missing) dependents: [service jboss.deployment.unit."apirest_war_exploded.war".deploymentCompleteService] 
WFLYCTL0186: Services which failed to start:  service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded 

[2017-07-14 02:57:24,302] Artifact apirest:war exploded: Error during artifact deployment. See server log for details. 
[2017-07-14 02:57:24,302] Artifact apirest:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./apirest_war_exploded" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./apirest_war_exploded: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    Caused by: java.lang.NoClassDefFoundError: com/google/common/base/Function 
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.Function from [Module \"deployment.apirest_war_exploded.war:main\" from Service Module Loader]"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./apirest_war_exploded"],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined} 
+0

嘗試在路徑中使用'/路徑(「/ devices」)' – tima

+0

當前發佈的異常堆棧跟蹤是一個紅色的鯡魚,因爲它是由不正確捆綁的庫導致的,不需要捆綁。請反過來,而是發佈無法訪問資源的部署日誌記錄。 – Gimby

+0

@tima我已經試過了,它不會改變一件事情。 – Phoste

回答

0

首先,你不需要任何REST實現罐子(如澤西島)添加到您的應用程序因爲Java EE 7級的服務器,例如WildFly和GlassFish免費提供。

問題的癥結在於您的URL缺少應用程序的上下文路徑(在您引用的教程中爲rest_glassfish_hello_world_war_exploded)。

即。正確的服務URL應該是這樣的:

http://localhost:8080/rest_glassfish_hello_world_war_exploded /api/v2.0/devices

其中rest_glassfish_hello_world_war_exploded應與實際的應用程序的名稱來代替,如果是不同的。

+0

那麼,我可以通過http:// localhost:8080/api/v2.0訪問index.jsp。 – Phoste

+0

您是否明確地將您的應用程序配置爲可從根「/」上下文訪問? –