I am trying to create a standalone web application using Spring Boot and Thymeleaf. The application works fine from IntelliJ IDEA, but I can not start the jar myself. Apparently templates are not included.
My project is structured as follows:
โโโ src
โ โโโ main
โ โโโ java
โ โ โโโ my
โ โ โโโ domain
โ โ โโโ application
โ โ โโโ domain
โ โ โโโ service
โ โ โโโ web
โ โ โโโ ApplicationConfig.java
โ โ โโโ SecurityConfig.java
โ โ โโโ ThymeleafConfig.java
โ โ โโโ WebConfig.java
โ โโโ resources
โ โ โโโ application.properties
โ โ โโโ log4j.properties
โ โโโ webapp
โ โโโ resources
โ โ โโโ jquery.js
โ โ โโโ style.css
โ โโโ WEB-INF
โ โโโ views
โ โโโ layout.html
โ โโโ login.html
โ โโโ menu.html
โโโ pom.xml
ApplicationConfig:
@Bean
public DataSource dataSource() {
...
}
@Bean
public SessionBean sessionBean() {
return new SessionBean();
}
public static void main(String[] args) {
SpringApplication.run(ApplicationConfig.class, args);
}
ThymeleafConfig:
@Bean
public TemplateResolver templateResolver(){
ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/views/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine(){
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.addDialect(new LayoutDialect());
return templateEngine;
}
@Bean
public ViewResolver viewResolver(){
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver() ;
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setOrder(1);
return viewResolver;
}
WebConfig:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
I managed to include the WEB-INF folder by adding it as a resource in pom.xml, but the views are still not fixed.
source
share