Error 404 while deploying a java web app on WildFly

徘徊边缘 提交于 2020-12-07 05:01:46

问题


I was following a tutorial on https://www.youtube.com/watch?v=dmMdLW92hBA.

Everything was going fine until the last part where the index.xhtml was introduced in the project.

I get a 404 error in the browser and in the wildfly console log I get the following error:

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

My 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>

I created an empty beans.xml just like in the tutorial.

Contents of my 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;
    }


}

回答1:


I downloaded the code base as well as WildFly 10.1.0.Final server. I was also facing the same issue.

Root Cause: The annotations @ApplicationPath and @Path are used in the same class that was creating the issue.

  • @ApplicationPath is used to provide base URI path for the total application.

  • @Path is used for individual URI path for custom controller class or class methods.

This RestService.java class was creating problem.

Modify the RestService.java (remove @ApplicationPath from this class) :

@Path("/MyRestService")
public class RestService {

    // 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");
    }

}

I have added a new class RestApp.java. The code :

@ApplicationPath("/resources")
public class RestApp extends Application {

}

Updated project structure :

Wildfly log (Success Deployment):

21:05:09,997 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) WFLYDS0013: Started FileSystemDeploymentService for directory C:\Users\Anish\Downloads\wildfly-10.1.0.Final\wildfly-10.1.0.Final\standalone\deployments
21:05:10,157 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0027: Starting deployment of "RestExample.war" (runtime-name: "RestExample.war")
21:05:10,312 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-1) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.4.Final
21:05:10,432 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 63) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
21:05:10,434 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 60) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
21:05:10,473 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 60) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
21:05:10,476 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 63) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
21:05:10,431 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
21:05:10,512 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 65) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
21:05:12,754 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
21:05:13,012 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
21:05:13,434 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443
21:05:13,603 INFO  [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBossWS 5.1.5.Final (Apache CXF 3.1.6)
21:05:14,003 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment RestExample.war
21:05:14,103 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.2.4.Final
21:05:14,443 INFO  [org.jboss.weld.Version] (MSC service thread 1-4) WELD-000900: 2.3.5 (Final)
21:05:15,748 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 59) Initializing Mojarra 2.2.13.SP1 20160303-1204 for context '/RestExample'
21:05:16,915 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 59) RESTEASY002225: Deploying javax.ws.rs.core.Application: class de.dks.ws.RestApp$Proxy$_$$_WeldClientProxy
21:05:17,050 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 59) WFLYUT0021: Registered web context: /RestExample
21:05:17,144 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "RestExample.war" (runtime-name : "RestExample.war")
21:05:17,304 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
21:05:17,305 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
21:05:17,310 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 13646ms - Started 435 of 683 services (404 services are lazy, passive or on-demand)

Screenshot :

Screenshot for RestClient :

By clicking on Call Webservice generate outputs :

Note: Don't forget to add these jars javax.faces.api-2.2.jar and javax.ws.rs-api-2.0.1.jar in your project WebContent/WEB-INF/lib.

Modified project link : https://github.com/anish-fullstack/RestExample



来源:https://stackoverflow.com/questions/60997046/error-404-while-deploying-a-java-web-app-on-wildfly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!