简体   繁体   中英

Spring Boot 1.5.2 sample returns 404

So I pulled down the Spring Boot Sample Web JSP example. I imported into Eclipse and I tweaked the POM so that it pulled in the parent POM properly but everything else is untouched. But when I hit the URL I get a 404. Below is the POM and is the only thing I've changed. I'm using Eclipse Luna to run it as a Spring App. The log didn't seem to show anything other than resource not found. Verified that the controller's method is getting called, so it's after the "welcome" view name being returned.

<?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>
    <parent>
        <!-- Your own application should inherit from spring-boot-starter-parent -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath />
    </parent>
    <artifactId>spring-boot-sample-web-jsp</artifactId>
    <packaging>war</packaging>
    <name>Spring Boot Web JSP Sample</name>
    <description>Spring Boot Web JSP Sample</description>
    <url>http://projects.spring.io/spring-boot/</url>
    <organization>
        <name>Pivotal Software, Inc.</name>
        <url>http://www.spring.io</url>
    </organization>
    <properties>
        <java.version>1.7</java.version>
        <main.basedir>${basedir}/../..</main.basedir>
        <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
    </properties>
    <dependencies>
        <!-- Compile -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>
        <!-- Provided -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <useSystemClassLoader>false</useSystemClassLoader>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And this is a snippet of my log

.w.s.m.m.a.ServletInvocableHandlerMethod : Method [sample.jsp.WelcomeController.welcome] returned [welcome]
o.s.w.s.v.ContentNegotiatingViewResolver : Requested media types are [text/html, application/xhtml+xml, image/webp, application/xml;q=0.9, */*;q=0.8] based on Accept header types and producible media types [*/*])
o.s.w.servlet.view.BeanNameViewResolver  : No matching bean found for view name 'welcome'
o.s.b.f.s.DefaultListableBeanFactory     : Invoking afterPropertiesSet() on bean with name 'welcome'
o.s.w.s.v.InternalResourceViewResolver   : Cached view [welcome]
o.s.w.s.v.ContentNegotiatingViewResolver : Returning [org.springframework.web.servlet.view.JstlView: name 'welcome'; URL [/WEB-INF/jsp/welcome.jsp]] based on requested media type 'text/html'
o.s.web.servlet.DispatcherServlet        : Rendering view [org.springframework.web.servlet.view.JstlView: name 'welcome'; URL [/WEB-INF/jsp/welcome.jsp]] in DispatcherServlet with name 'dispatcherServlet'
o.s.web.servlet.view.JstlView            : Rendering view with name 'welcome' with model {time=Wed Mar 15 13:59:42 EDT 2017, message=Hello Phil} and static attributes {}
o.s.web.servlet.view.JstlView            : Added model object 'time' of type [java.util.Date] to request in view with name 'welcome'
o.s.web.servlet.view.JstlView            : Added model object 'message' of type [java.lang.String] to request in view with name 'welcome'
o.s.web.servlet.view.JstlView            : Forwarding to resource [/WEB-INF/jsp/welcome.jsp] in InternalResourceView 'welcome'
o.apache.catalina.core.StandardWrapper   :   Returning non-STM instance
o.s.web.servlet.DispatcherServlet        : Bound request context to thread: org.apache.catalina.core.ApplicationHttpRequest@1077e52
o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/WEB-INF/jsp/welcome.jsp]
o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@6cee48] in DispatcherServlet with name 'dispatcherServlet'
o.s.w.s.handler.SimpleUrlHandlerMapping  : No handler mapping found for [/WEB-INF/jsp/welcome.jsp]
o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@190641d] in DispatcherServlet with name 'dispatcherServlet'
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /WEB-INF/jsp/welcome.jsp
o.a.c.loader.WebappClassLoaderBase       : getResource(org/springframework/mail/javamail/mime.types)
o.a.c.loader.WebappClassLoaderBase       :   Delegating to parent classloader sun.misc.Launcher$AppClassLoader@a4be02
o.a.c.loader.WebappClassLoaderBase       :     findResource(org/springframework/mail/javamail/mime.types)
o.a.c.loader.WebappClassLoaderBase       :     --> Resource not found, returning null
o.a.c.loader.WebappClassLoaderBase       :   --> Resource not found, returning null
.PathExtensionContentNegotiationStrategy : Loading default Java Activation Framework FileTypeMap
javax.activation                         : MimetypesFileTypeMap: load HOME
javax.activation                         : MimetypesFileTypeMap: load SYS
javax.activation                         : MimetypesFileTypeMap: load JAR
o.a.c.loader.WebappClassLoaderBase       :     findResources(META-INF/mime.types)

Try to remove the <scope>provide</scope> element of spring-boot-starter-tomcat and tomcat-embed-jasper . I met this problem too and it fix my issue by doing that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM