首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ViewResolver -boot-thymeleaf starter-“圆形视图启动,检查您的spring设置!错误

ViewResolver -boot-thymeleaf starter-“圆形视图启动,检查您的spring设置!错误
EN

Stack Overflow用户
提问于 2019-05-22 06:20:32
回答 1查看 184关注 0票数 0

我已经使用spring-security-saml2实现了saml-adfs服务提供者。SAML-ADFS身份验证正常进行。认证后,我试图将其重定向到一个登录页面,其中有几个变量,如UserID动态填充基于登录的用户信息。对于html页面的渲染,我使用spring-boot-started-thymeleaf lib。我已经阅读了各种文章,并完成了下面的配置。我所有的html文件都在src/main/resources/template中。

我得到“环视图路径登陆,检查你的ViewResolver设置!错误。

代码语言:javascript
复制
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";
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-22 15:07:52

首先检查您的视图解析器是否已配置为correctly.Try配置您的胸腺叶视图解析器,如下所示:

代码语言:javascript
复制
@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,这将解决您的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56247029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档