首页 > 解决方案 > 如何解决 Spring Boot 中的 Whitelabel 错误页面

问题描述

我在我的应用程序中遵循了spring boot的官方 文件和包结构。但我仍然收到白标签页面错误。

在此处输入图像描述

下面是我如何放置我的代码以及如何排列文件和文件夹的图像。

控制器

 @Controller
 public class UserController  { 
 @RequestMapping("/")
 public String index(HttpServletRequest request){
    request.setAttribute("mode", "MODE_HOME");
    return  "homepage";
}}

主页.jsp

<body>
<c:choose>
<c:when test="${mode=='MODE_HOME'}">
<h1>Mambo, this is home page </h1>
</c:when> </c:choose>
</body>

应用程序属性

spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp

pom.xml

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>  
<scope>provided</scope>     
</dependency>

<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

在此处输入图像描述

我花了一整天的时间试图弄清楚我错过了什么,但没有成功。

标签: springspring-bootspring-mvc

解决方案


扩展WebSecurityConfigurerAdapter并覆盖configure(HttpSecurity http)以定义哪些路由不需要身份验证:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers(HttpMethod.GET, "/**").permitAll()
                // add more matches here
            .anyRequest().authenticated()
        ;
    }
}

推荐阅读