我已经开始使用spring boot并试图创建这个基本程序 但它给出了白色错误页面:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Mar 21 23:06:15 IST 2018
There was an unexpected error (type=Not Found, status=404).
No message available
这是pom.xml文件的依赖项部分
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
的index.jsp:
<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head></head>
<body>
Hello User....
</body>
</html>
Application.properties文件:
spring.mvc.view.prefix: /WEB-INF/views/
spring.mvc.view.suffix: .jsp
以下是控制器类:
package com.whiteboard.banking;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/")
public String index(){
return "index";
}
}
我尝试在index方法中记录消息并且它正在提供日志记录,这意味着调用了此方法但是index.jsp没有呈现。
有人可以告诉我错误的原因吗?
答案 0 :(得分:0)
默认情况下,Spring Boot从名为/ static(或/ public或/ resources或/ META-INF / resources)的目录中提供静态内容。您可以通过实施WebMvcConfigurer
或扩展WebMvcConfigurerAdapter
然后覆盖addResourceHandlers
来覆盖这些内容。
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations(new String[] {"classpath:/", "classpath:/public/"});
}
}
也许这可以帮助你spring static content
答案 1 :(得分:0)