【问题标题】:Home page not displayed in Spring BootSpring Boot 中不显示主页
【发布时间】:2015-06-05 18:23:23
【问题描述】:

在 Spring Boot (v1.2.3.RELEASE) 中在 STS 中开发第一个 Web 应用程序时,打开此 url (http://localhost:8080/riyan/) 时出现以下错误:

错误:

此应用程序没有明确的 /error 映射,因此您将其视为后备。 2015 年 6 月 5 日星期五 23:08:55 PKT 出现意外错误(类型=未找到,状态=404)。 没有可用的消息

Application.properties

logging.config = ${app.root.dir}/config/logback.xml
spring.view.prefix = /WEB-INF/views/
spring.view.suffix = .jsp
spring.datasource.url=jdbc:hsqldb:file:${app.root.dir}/data/accounts;crypt_key=901a6105813eb65326bf35790a965432;crypt_type=blowfish;hsqldb.write_delay=false;create=false;sql.syntax_ora=true

spring.datasource.username=accounts
spring.datasource.password=accounts
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none

spring.datasource-internal.jpa.database-platform=org.hibernate.dialect.HSQLDialect

HomeController.java

package com.riyan.controller;

import org.springframework.web.bind.annotation.RequestMapping; 
import  org.springframework.web.bind.annotation.RestController;

@RestController 
public class HomeController {

    @RequestMapping("/")
    public String getHomePage() {
        return "login";
    }

}

JSP:

login.jsp 存在于 WEB-INF->views->login.jsp

以下是关键服务器控制台的内容:

控制台输出:

23:08:47.239 [localhost-startStop-1] INFO  org.apache.tiles.access.TilesAccess - Publishing TilesContext for context: org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext

23:08:47.989 [localhost-startStop-1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5596ab: startup date [Fri Jun 05 23:08:32 PKT 2015]; root of context hierarchy

23:08:48.333 [localhost-startStop-1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)

23:08:48.333 [localhost-startStop-1] INFO  o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)

23:08:48.427 [localhost-startStop-1] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

23:08:48.427 [localhost-startStop-1] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

23:08:48.614 [localhost-startStop-1] INFO  o.s.w.s.h.SimpleUrlHandlerMapping - Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

如果需要任何进一步的信息,请告诉我。

【问题讨论】:

    标签: spring model-view-controller spring-boot


    【解决方案1】:

    我在您的配置中没有看到任何将服务器上下文设置为“/riyan”的内容。您应该将其添加到您的 application.properties

    server.contextPath=/riyan
    

    否则您可能会发现您的实际 login.jps 位于 http://localhost:8080/

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 2020-10-24
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 2018-02-26
      • 2019-05-15
      相关资源
      最近更新 更多