Spring Boot Patterns Not Allowed

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.

+4
source share
1 answer

Have you tried to completely delete the WEB-INF folder and paste everything into resources, as is done in this guide?

+1
source

Source: https://habr.com/ru/post/1534312/


All Articles