我已经使用spring-security-saml2实现了saml-adfs服务提供者。SAML-ADFS身份验证正常进行。认证后,我试图将其重定向到一个登录页面,其中有几个变量,如UserID动态填充基于登录的用户信息。对于html页面的渲染,我使用spring-boot-started-thymeleaf lib。我已经阅读了各种文章,并完成了下面的配置。我所有的html文件都在src/main/resources/template中。
我得到“环视图路径登陆,检查你的ViewResolver设置!错误。
If I change it to a static html page, which is present in src/main/resources/static folder, then it is loading the content.
Please guide me how I can resolve this issue. I have dependency of spring-boot-starter-web and spring-boot-starter-thymeleaf in my build.gradle
landing.html page
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Landing!</title>
</head>
<body>
<h1>You are logged as <span th:text="${username}">null</span>!</h1>
<p>
<a th:href="@{/saml/logout}">Global Logout</a><br/>
<a th:href="@{/saml/logout?local=true}">Local Logout</a>
</p>
</body>
</html>
@Controller
public class LandingController {
@RequestMapping("/landing")`enter code here`
public String landing(@CurrentUser User user, Model model) {
model.addAttribute("username", user.getUsername());
return "landing";
}发布于 2019-05-22 15:07:52
首先检查您的视图解析器是否已配置为correctly.Try配置您的胸腺叶视图解析器,如下所示:
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Bean
public ClassLoaderTemplateResolver templateResolver() {
var templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("templates/");
templateResolver.setCacheable(false);
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setTemplateEngineMessageSource(messageSource());
return templateEngine;
}
@Bean
public ViewResolver viewResolver() {
var viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setCharacterEncoding("UTF-8");
return viewResolver;
}
}这是基本配置,您可以根据您的项目结构在此配置中更改模板的位置等。
当您提供此配置时,Thymeleafview解析器将处理解析用于访问html的uri,这将解决您的问题。
https://stackoverflow.com/questions/56247029
复制相似问题