HTTP状态404 - 未找到 - Spring MVC

时间:2017-07-18 10:44:02

标签: java spring maven spring-mvc

我在Spring MVC中创建简单的应用程序,我有问题。 HTTP状态404 - 未找到这是我在spring mvc中的第一个应用程序,我现在不会发生什么; / 这是我的代码和pom.xml RootConfig:

@Configuration
public class RootConfig {
}

WebConfig:

@Configuration
@EnableWebMvc
@ComponentScan("com.mathew")
public class WebConfig extends WebMvcConfigurerAdapter {
    @Bean
    public InternalResourceViewResolver resolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/");
        resolver.setSuffix(".jsp");
        return resolver;
    }
}

WebInit:

@Configuration
public class WebInit extends AbstractAnnotationConfigDispatcherServletInitializer {

    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{RootConfig.class};
    }

    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{WebConfig.class};
    }

    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}

HomeController:

@Controller
public class HomeController {
    @RequestMapping(value = "/")
    public String home(){
        return "home";
    }
}

我的文件是pom.xml:

<packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

任何人都可以帮助我吗?

编辑: 我的日志:

"C:\Program Files\apache-tomcat-9.0.0.M22\bin\catalina.bat" run
[2017-07-18 03:12:45,274] Artifact AppSpring: Server is not connected. Deploy is not available.
Using CATALINA_BASE:   "C:\Users\dell\.IntelliJIdea2017.1\system\tomcat\Unnamed_AppSpring"
Using CATALINA_HOME:   "C:\Program Files\apache-tomcat-9.0.0.M22"
Using CATALINA_TMPDIR: "C:\Program Files\apache-tomcat-9.0.0.M22\temp"
Using JRE_HOME:        "C:\Program Files\Java\jdk1.8.0_131"
Using CLASSPATH:       "C:\Program Files\apache-tomcat-9.0.0.M22\bin\bootstrap.jar;C:\Program Files\apache-tomcat-9.0.0.M22\bin\tomcat-juli.jar"
18-Jul-2017 15:12:46.094 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.0.M22
18-Jul-2017 15:12:46.095 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Jun 21 2017 09:44:18 UTC
18-Jul-2017 15:12:46.095 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.0.0
18-Jul-2017 15:12:46.095 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
18-Jul-2017 15:12:46.095 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
18-Jul-2017 15:12:46.095 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
18-Jul-2017 15:12:46.095 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_131\jre
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_131-b11
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\dell\.IntelliJIdea2017.1\system\tomcat\Unnamed_AppSpring
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         C:\Program Files\apache-tomcat-9.0.0.M22
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\dell\.IntelliJIdea2017.1\system\tomcat\Unnamed_AppSpring\conf\logging.properties
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
18-Jul-2017 15:12:46.096 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.rmi.server.hostname=127.0.0.1
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\Users\dell\.IntelliJIdea2017.1\system\tomcat\Unnamed_AppSpring
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\Program Files\apache-tomcat-9.0.0.M22
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\Program Files\apache-tomcat-9.0.0.M22\temp
18-Jul-2017 15:12:46.097 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.12] using APR version [1.5.2].
18-Jul-2017 15:12:46.098 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
18-Jul-2017 15:12:46.098 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
18-Jul-2017 15:12:46.816 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2k  26 Jan 2017]
18-Jul-2017 15:12:46.933 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
18-Jul-2017 15:12:46.951 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
18-Jul-2017 15:12:46.954 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
18-Jul-2017 15:12:46.956 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
18-Jul-2017 15:12:46.956 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1185 ms
18-Jul-2017 15:12:46.983 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
18-Jul-2017 15:12:46.983 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.0.M22
18-Jul-2017 15:12:46.993 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
18-Jul-2017 15:12:47.005 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
18-Jul-2017 15:12:47.008 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 50 ms
Connected to server
[2017-07-18 03:12:47,354] Artifact AppSpring: Artifact is being deployed, please wait...
[2017-07-18 03:12:47,848] Artifact AppSpring: Artifact is deployed successfully
[2017-07-18 03:12:47,849] Artifact AppSpring: Deploy took 495 milliseconds
18-Jul-2017 15:12:56.996 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Program Files\apache-tomcat-9.0.0.M22\webapps\manager]
18-Jul-2017 15:12:57.034 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Program Files\apache-tomcat-9.0.0.M22\webapps\manager] has finished in [37] ms

0 个答案:

没有答案