嗨,我正在开发一个restapi与intellij遵循官方文件。
但我得到一个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 not found错误。
当我看到这件文物时,我注意到泽西岛图书馆不在战争中。但是,当我尝试将它添加到war中时,当我尝试部署应用程序时会出现异常。
我得到的例外:
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}
1条答案
按热度按时间iklwldmw1#
首先,您不需要向应用程序添加任何rest实现jar(比如jersey),因为javaee7服务器(比如wildfly和glassfish)是免费的。
问题的关键在于,url缺少应用程序的上下文路径(即
rest_glassfish_hello_world_war_exploded
在您引用的教程中)。即,正确的服务url应类似于:
http://localhost:8080/rest\u glassfish\u hello\u world\u war\u exploded/api/v2.0/devices
哪里
rest_glassfish_hello_world_war_exploded
如果实际应用程序名称不同,则应替换为实际应用程序名称。