在WildFly上部署Java Web应用程序时的404

问题描述 投票:1回答:1

我一直在遵循以下教程https://www.youtube.com/watch?v=dmMdLW92hBA,直到一切顺利,直到引入index.xhtml的最后一部分为止。我在浏览器和控制台中收到404错误,得到以下错误:

18:24:52,128 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 64) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./RestExample: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./RestExample: org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:85)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
    at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:689)
    at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:90)
    at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:165)
    at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:83)
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:125)
    at org.jboss.weld.proxies.RestService$Proxy$_$$_WeldClientProxy.getClasses(Unknown Source)
    at org.jboss.resteasy.spi.ResteasyDeployment.processApplication(ResteasyDeployment.java:490)
    at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:336)
    at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:250)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:113)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
    at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
    at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:250)
    at io.undertow.servlet.core.ManagedServlet.createServlet(ManagedServlet.java:133)
    at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:546)
    at io.undertow.servlet.core.DeploymentManagerImpl$2.call(DeploymentManagerImpl.java:517)
    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.start(DeploymentManagerImpl.java:559)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:101)
    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
    ... 6 more

18:24:52,133 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "RestExample.war")]) - failure description: {
    "WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./RestExample" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./RestExample: org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
    Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped"},
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./RestExample"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => undefined
}
WFLYCTL0184:    New missing/unsatisfied dependencies:
      service jboss.deployment.unit."RestExample.war".component."com.sun.faces.config.ConfigureListener".START (missing) dependents: [service jboss.deployment.unit."RestExample.war".deploymentCompleteService] 
      service jboss.deployment.unit."RestExample.war".component."javax.faces.webapp.FacesServlet".START (missing) dependents: [service jboss.deployment.unit."RestExample.war".deploymentCompleteService] 
      service jboss.deployment.unit."RestExample.war".component."javax.faces.webapp.FacetTag".START (missing) dependents: [service jboss.deployment.unit."RestExample.war".deploymentCompleteService] 
      service jboss.deployment.unit."RestExample.war".component."managed-bean.RestClient".START (missing) dependents: [service jboss.deployment.unit."RestExample.war".deploymentCompleteService] 
      service jboss.deployment.unit."RestExample.war".component."org.jboss.weld.servlet.WeldInitialListener".START (missing) dependents: [service jboss.deployment.unit."RestExample.war".deploymentCompleteService] 
WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./RestExample

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>RestExample</display-name>
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
  </welcome-file-list>

  <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

就像在本教程中一样,我创建了一个空的beans.xml。

我的index.xhtml的内容:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<h:head>
</h:head>
<h:body>
    <h:form>
        <h:commandButton value="Call Webservice" action="#{restClient.call()}" />
    </h:form>
</h:body>
</html>

RestClient.java:

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

@ApplicationScoped
@ManagedBean
public class RestClient {

    public void call() {
        Client client = ClientBuilder.newClient();

        SimpleObject o = client.target("http://localhost:8080/RestExample/resources/MyRestService/object").request().get(SimpleObject.class);

        System.out.println(o);
    }
}

RestService.java:

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Path("/MyRestService")
@ApplicationPath("/resources")
public class RestService extends Application {
    //  http://localhost:8080/RestExample/resources/MyRestService/sayHello
    @GET
    @Path("/sayHello")
    public String getHelloMsg() {
        return "Hello World";
    }

    @GET
    @Path("/echo")
    public Response getEchoMsg(@QueryParam("message") String msg) {
        return Response.ok("Your message was: " + msg).build();
    }

    @GET
    @Path("/object")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public SimpleObject getObject() {
        return new SimpleObject(1, "Test");
    }
}

SimpleObject.java:

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class SimpleObject {

    private int id;
    private String name;

    public SimpleObject() {

    }

    public SimpleObject(int id, String name) {
        super();
        this.id = id;
        this.name = name;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }


}

java wildfly
1个回答
0
投票

@ApplicationScoped替换@RequestScoped

将代码更新为此:

@RequestScoped
@ManagedBean
public class RestClient {

    public void call() {
        Client client = ClientBuilder.newClient();

        SimpleObject o = client.target("http://localhost:8080/RestExample/resources/MyRestService/object").request().get(SimpleObject.class);

        System.out.println(o);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.