简体   繁体   English

Thymeleaf:org.thymeleaf.exceptions.TemplateInputException

[英]Thymeleaf : org.thymeleaf.exceptions.TemplateInputException

i am trying to use thymeleaf 3.0.7.RELEASE with spring mvc java based configuration. 我试图在基于Spring 3.0.7.RELEASE Java的配置中使用thymeleaf 3.0.7.RELEASE

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.sagar")
public class MvcConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware{

    @Autowired
    RoleToUserProfileConverter roleToUserProfileConverter;

    private ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Bean
    public ViewResolver viewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine());
        resolver.setCharacterEncoding("UTF-8");
        return resolver;
    }

    @Bean
    public TemplateEngine templateEngine() {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setEnableSpringELCompiler(true);
        engine.setTemplateResolver(templateResolver());
        return engine;
    }

    private ITemplateResolver templateResolver() {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(applicationContext);
        resolver.setPrefix("/WEB-INF/templates/");
        resolver.setTemplateMode(TemplateMode.HTML);
        return resolver;
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("/static/**").addResourceLocations("/static/");

    }
}

methods inside springsecurity configuration class. springsecurity配置类中的方法。

 @Autowired
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth)
     throws Exception{
        auth.userDetailsService(userDetailsService);
        auth.authenticationProvider(authenticationProvider());
    }

    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/").permitAll()
                .antMatchers( "/admin/list")
                .access("hasRole('USER') or hasRole('ADMIN') or hasRole('DBA')")
                .antMatchers("/newuser/**", "/delete-user-*").access("hasRole
                ('ADMIN')").antMatchers("/edit-user-*")
                .access("hasRole('ADMIN') or hasRole('DBA')").and().formLogin()
                .loginPage("/login")
                .loginProcessingUrl("/login").usernameParameter("ssoId").
                passwordParameter("password").and()
                .rememberMe().rememberMeParameter("remember-me").
                tokenRepository(tokenRepository)
                .tokenValiditySeconds(86400).and().csrf().and().exceptionHandling()
                .accessDeniedPage("/Access_Denied");
    }

and my home.html file 和我的home.html文件

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

this is home page using thymeleaf

</body>
</html>

my pom.xml dependencies includes 我的pom.xml依赖项包括

<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf-spring4</artifactId>
  <version>3.0.7.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>3.0.7.RELEASE</version>
</dependency>

the spring security version is 4.2.3.RELEASE and spring version is 4.3.9.RELEASE spring安全版本是4.2.3.RELEASE ,spring版本是4.3.9.RELEASE

the errors i am getting are:- 我得到的错误是:

Message Request processing failed; nested exception is 
org.thymeleaf.exceptions.TemplateInputException: 
An error happened during template parsing 
(template: "ServletContext resource [/WEB-INF/templates/home]")


Root Cause

java.io.FileNotFoundException: Could not open ServletContext 
resource [/WEB-INF/templates/home]

Root Cause

org.thymeleaf.exceptions.TemplateInputException: 
An error happened during template parsing
 (template: "ServletContext resource [/WEB-INF/templates/home]")

The templateResolver method needs to be fixed. templateResolver方法需要修复。

  1. Try setting suffix 尝试设置后缀

     resolver.setSuffix(".html"); 
  2. Try setting correct TemplateMode 尝试设置正确的TemplateMode

     resolver.setTemplateMode("HTML5"); 

I think this should solve the problem 我认为这应该解决问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调试org.thymeleaf.exceptions.TemplateInputException? - How to debug org.thymeleaf.exceptions.TemplateInputException? org.thymeleaf.exceptions.TemplateInputException:Spring Boot - org.thymeleaf.exceptions.TemplateInputException: Spring Boot springboot项目的问题:org.thymeleaf.exceptions.TemplateInputException - issue with springboot project : org.thymeleaf.exceptions.TemplateInputException Thyemleaf 嵌套迭代触发器 org.thymeleaf.exceptions.TemplateInputException - Thyemleaf nested iteration triggers org.thymeleaf.exceptions.TemplateInputException org.thymeleaf.exceptions.TemplateInputException:解决片段错误:无法解析模板或片段 - org.thymeleaf.exceptions.TemplateInputException: Error resolving fragment: template or fragment could not be resolved 我的spring-boot应用程序给出以下错误“ org.thymeleaf.exceptions.TemplateInputException:” - My spring-boot app gives the following error “org.thymeleaf.exceptions.TemplateInputException:” org.thymeleaf.exceptions.TemplateInputException:异常分析文档:template =“ login”,第36行-第3列 - org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template=“login”, line 36 - column 3 如何摆脱 org.thymeleaf.exceptions.TemplateInputException: 同时使用 thymeleaf 表达式以引导卡的形式打印数据? - how to get rid of org.thymeleaf.exceptions.TemplateInputException: while using thymeleaf expression to print data in form of bootstrap cards? Spring 启动测试 Thymeleaf org.thymeleaf.exceptions.TemplateProcessingException - Spring Boot Testing Thymeleaf org.thymeleaf.exceptions.TemplateProcessingException org.thymeleaf.exceptions.TemplateProcessingException:串联 href - org.thymeleaf.exceptions.TemplateProcessingException: Concatenation href
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM