账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    啟動Maven出錯(HTTP 404和No mapping found...)
    30
    0

    各位大神們好,我嘗試啟動Maven,以下是我將別人的代碼複製下來實行,但卻跑出的錯誤:

    警告: No mapping found for HTTP request with URI [/mavenproject2] in DispatcherServlet with name 'dispatcher'
    HTTP404, 請大神幫忙解惑!!謝謝!!

    web.xml:

    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/javaee"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
             version="3.0">
      <display-name>SpringDemo</display-name>
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>
                org.springframework.web.servlet.DispatcherServlet
            </servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/mvc-config.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    </web-app>
    

    mvc.config.xml:

    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans     
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/mvc 
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context.xsd">
         
        <context:component-scan base-package="allen0818.tutorial.*" />
        <mvc:annotation-driven />
        <mvc:resources mapping="/*.html" location="/" />
        <mvc:resources mapping="/js/**" location="/js/" />
         
        <bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/" />
            <property name="suffix" value=".jsp" />
        </bean>
     
    </beans>
    

    MainController.java

    package allen0818.tutorial.controller;
     
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
     
    /**
     *
     * @author allen0818
     */
    @Controller
    public class MainController {
      @RequestMapping(value = "/helloSpring")
      public void sayHello() {
        System.out.println("MainController executes sayHello function ...");
      }
    }
    

    helloSpring

    <%
        Document   : helloSpring
        Created on : 2018/10/19, 下午 10:03:59
        Author     : Vivi
    %>
    
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Hello Spring MVC</title>
        </head>
        <body>
            <h1>Hello, Spring MVC World!</h1>
        </body>
    </html>
    

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.mycompany</groupId>
        <artifactId>mavenproject2</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <name>mavenproject2</name>
    
        <properties>
            <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>5.0.10.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.9.6</version>
            </dependency>
            <dependency>
                <groupId>jstl</groupId>
                <artifactId>jstl</artifactId>
                <version>1.2</version>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${endorsed.dir}</outputDirectory>
                                <silent>true</silent>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>javax</groupId>
                                        <artifactId>javaee-endorsed-api</artifactId>
                                        <version>7.0</version>
                                        <type>jar</type>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    
    </project>
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • ℡音符流濄の回忆 普通会员 1楼

      HTTP 404错误通常表示请求的URL不存在。这可能是由于以下原因:

      1. 请求的URL已经更改:如果你曾经更改过URL,那么Maven可能会将你的更改包含在404错误中。例如,如果你删除了一个已经存在的文件,Maven可能会创建一个新的URL来表示该文件。

      2. 模板或布局文件不存在:Maven的模板和布局文件是用于生成XML或HTML的文件。如果这些文件不存在,那么Maven就会返回404错误。

      3. 路径错误:如果你的项目包含多个目录,那么路径错误可能是问题的根源。你需要确保你的URL指向正确的目录。

      4. 模块依赖冲突:如果你的项目包含多个模块,那么模块之间的依赖可能会导致404错误。你需要检查你的模块依赖关系,确保它们都是正确的。

      解决这个问题的一种方法是尝试刷新页面。如果你已经尝试过刷新页面,但是问题仍然存在,那么可能是Maven或其他相关库的问题。在这种情况下,你可能需要尝试更新你的依赖或查找其他解决方案。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部