spring - 如何解决 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>
我花了一整天的时间试图弄清楚我错过了什么,但没有成功。
解决方案
扩展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()
;
}
}
推荐阅读
- c# - 以正确的顺序复制位
- angular - Angular 4 如何在单击按钮时打开新选项卡并在会话中设置变量。并防止当前页面冻结
- laravel - 如何在 laravel 中向数据表列添加路由链接?
- uwp - Dispatcher.RunOnUIThread 需要时间来运行代码
- ansible - callback_plugins 目录中的 Ansible 插件多次运行
- jenkins - 我在 ec2 机器上运行 jenkins 作业我想将所有作业迁移到 docker 容器中
- node.js - 护照 jwt 与护照本地会话
- excel - 如何将带有 VBA 宏的 Excel 工作表从一张工作表复制到同一工作簿中的另一张工作表
- html - 如何将 iframe 大小包装在引导模式中
- go - 从 html 标签中清除字符串的最佳方法是什么