Skip to content

Instantly share code, notes, and snippets.

@NeilAlishev
Created April 1, 2020 12:44
Show Gist options
  • Save NeilAlishev/11642fd955e22f4bf435ea43b32e0ddb to your computer and use it in GitHub Desktop.
Save NeilAlishev/11642fd955e22f4bf435ea43b32e0ddb to your computer and use it in GitHub Desktop.
@Configuration
@ComponentScan("ru.alishev.springcourse")
@EnableWebMvc
public class SpringConfig implements WebMvcConfigurer {
private final ApplicationContext applicationContext;
@Autowired
public SpringConfig(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(applicationContext);
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
registry.viewResolver(resolver);
}
}
@monolut
Copy link

monolut commented Apr 10, 2025

Почему на запрос: http://localhost:8080/hello-world Выдаёт: HTTP Status 500 – Внутренняя ошибка сервера ??? Всё делал по урокам. И на предыдущем уроке через xml настройки такая же ерунда была.

Версия Thymeleaf Sping5 не может работать с современной версией Spring6, поменяй версию Thymeleaf - spring с 5 на 6 и заработаеет

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment