java - 映射到应用程序根“/”失败,但除此之外正在工作
问题描述
我正在使用 Spring Boot 2.5.2。我配置了所有东西(不是安全性,它是自动配置的,需要将所有配置从 XML 转换为 Java。身份验证通过 LDAP 工作)并且工作正常,除了一件事,即映射到/
-> redirect:/main
。
注意:这是从 Spring 迁移到带有.jsp
as 视图的 Spring Boot。
下面是 XML 中的映射:
<mvc:view-controller path="/" view-name="redirect:/main" />
以上在 Spring 中正常工作,但是当使用如下 Java 代码转换为 Spring Boot 时,这种特定情况不起作用:
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("redirect:/main");
}
}
注意:如果我设置addViewController
了其他类似的东西,/documentation
那么它会成功重定向,但不会使用/
.
解决方案
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("/", "redirect:/main");
}
}
推荐阅读
- amazon-web-services - 目标响应时间 aws 指标如何工作
- powershell - 在文本文件中查找图片文件的路径,并将文件路径交给poshgram
- javascript - 使用 JQuery 将类添加到第 n 个孩子及其孩子
- javascript - 我应该总是“等待”每一个承诺吗?
- eclipse - Eclipse 2020-09 (4.17.0) GWT 客户端调试错误
- java - Java JDA如何检查消息是否超过2周
- javascript - 为什么我使用数组映射方法创建的选项具有空值(React)?
- sql - 使用 SQL Server Express 通过电子邮件发送查询结果
- mysql - 如何解决'Caused by: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x96\xA4 t...' for column 'campaign_name' at row 1' in mysql?
- javascript - 具有动态最大高度的 CSS 动画元素