得到警告为"[org.springframework.web.servlet.PageNotFound](默认任务1)没有GET/ProjectFE/“的映射. [英] getting an warning as" [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping for GET /ProjectFE/"

查看:301
本文介绍了得到警告为"[org.springframework.web.servlet.PageNotFound](默认任务1)没有GET/ProjectFE/“的映射.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,正如标题所述,我遇到一个错误:"[org.springframework.web.servlet.PageNotFound](默认任务1)没有GET/ProjectFE/的映射",我该如何解决呢?代码中也没有错误.

so as the title says I'm getting a 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.

这是我的代码:

web.xml文件-

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文件:

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文件:

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/

项目结构:

推荐答案

首先像这样安排web.xml

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

在定义contex-param时,不需要使用init-param相同的xml文件. 现在在spring-config.xml

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>

仔细查看<beans:property name="prefix" value="/Views/" />行.您的文件夹名称是Views,但是您定义了view.这就是为什么您可能会出错的原因.

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.

请大声喊叫.

这篇关于得到警告为"[org.springframework.web.servlet.PageNotFound](默认任务1)没有GET/ProjectFE/“的映射.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆