Spring Boot 1.5.2示例返回404

时间:2017-03-15 18:09:05

标签: java spring

所以我删除了Spring Boot Sample Web JSP示例。我导入了Eclipse并且我调整了POM,以便它正确地拉入父POM,但其他​​一切都没有被触及。但当我点击URL时,我得到了404.下面是POM,是我唯一改变的东西。我正在使用Eclipse Luna将其作为Spring App运行。除了找不到资源之外,日志似乎没有显示任何内容。验证控制器的方法是否被调用,因此它在返回“欢迎”视图名称之后。

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

这是我的日志片段

.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)

1 个答案:

答案 0 :(得分:0)

尝试删除<scope>provide</scope>spring-boot-starter-tomcat的{​​{1}}元素。 我也遇到了这个问题,并通过这样做解决了我的问题。