javaspring-mvcjbosswildfly-12

getting an warning as" [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping for GET /ProjectFE/"


so as the title says I'm getting an error a [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping for GET /ProjectFE/ how should I fix this? Also, there's no error in the code.

here is my code:

web.xml file-

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets 
    and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-config.xml
    </param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

spring-config.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd">

<annotation-driven />

<resources mapping="/resources/**" location="/resources/" />

<beans:bean 
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/views/" />
    <beans:property name="suffix" value=".jsp" />
 </beans:bean>

     <context:component-scan    base-package="controller" />        

 </beans:beans>

homepage.java file:

package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class HomeController {
        @RequestMapping(value="/", method=RequestMethod.GET)
    public String home()
    {
       return "homepage";
    }

 }

After running the code on server here's what i'm getting:

17:59:10,772 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found ProjectFE.war in deployment directory. To trigger deployment create a file called ProjectFE.war.dodeploy
17:59:10,822 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "ProjectFE.war" (runtime-name: "ProjectFE.war")
17:59:15,226 WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.http.server.reactive.ServletServerHttpResponse$ResponseAsyncListener due to an exception (enable DEBUG log level to see the cause)
17:59:15,227 WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.http.server.reactive.ServletHttpHandlerAdapter$HandlerResultAsyncListener due to an exception (enable DEBUG log level to see the cause)
17:59:15,230 WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
17:59:15,231 WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
17:59:15,234 WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.http.server.reactive.ServletServerHttpRequest$RequestAsyncListener due to an exception (enable DEBUG log level to see the cause)
17:59:15,251 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)
17:59:15,252 WARN  [org.jboss.weld.deployer] (MSC service thread 1-5) WFLYWELD0013: Deployment ProjectFE.war contains CDI annotations but no bean archive was found (no beans.xml or class with bean defining annotations was present).
17:59:15,274 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-6) WFLYJCA0018: Started Driver service with driver-name = ProjectFE.war_org.h2.Driver_1_4
17:59:15,306 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 74) No Spring WebApplicationInitializer types detected on classpath
17:59:15,308 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 74) Initializing Spring root WebApplicationContext
17:59:15,308 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 74) Root WebApplicationContext: initialization started
17:59:16,053 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 74) Root WebApplicationContext initialized in 745 ms
17:59:16,057 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 74) Initializing Mojarra 2.2.13.SP5  for context '/ProjectFE'
17:59:17,076 INFO  [io.undertow.servlet] (ServerService Thread Pool -- 74) Initializing Spring DispatcherServlet 'appServlet'
17:59:17,076 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 74) Initializing Servlet 'appServlet'
17:59:17,279 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 74) Completed initialization in 203 ms
17:59:17,280 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 74) WFLYUT0021: Registered web context: '/ProjectFE' for server 'default-server'
17:59:17,353 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "ProjectFE.war" (runtime-name : "ProjectFE.war")
18:00:14,061 WARN  [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping for GET /ProjectFE/

project structure: enter image description here


Solution

  • First of all arrange your web.xml like this

        <?xml version="1.0" encoding="UTF-8"?>
        <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    
        <!-- Processes application requests -->
        <servlet>
            <servlet-name>appServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>appServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                WEB-INF/spring-config.xml
            </param-value>
        </context-param>
       <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    </web-app>
    

    As you are defining contex-param you don't need to use init-param same xml file. Now change a little in spring-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans
    xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">
    
    <mvc:annotation-driven/>
    
    <resources mapping="/resources/**" location="/resources/" />
    
    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/Views/" />
        <beans:property name="suffix" value=".jsp" />
     </beans:bean>
    
      <context:component-scan    base-package="controller" />        
     </beans:beans>
    

    Look carefully in line <beans:property name="prefix" value="/Views/" />. Your folder name is Views but you defined view. That's why perhaps you are getting error.

    Give a shout if it works.