Шаблоны / представления Spring Boot не разрешены для JSP (JSP + HTML + thymeleaf) - PullRequest
0 голосов
/ 28 марта 2020

[TL: DR] Spring Boot правильно разрешает мои. html файлы из папки src / resources / templates, но не разрешает мои. jsp файлы из src / webapp / WEB-INF / jsp ( feed. jsp не разрешается).

Я проверил весь inte rnet, но не смог найти хорошего руководства, как заставить Spring Boot работать с. html (с тимилефом ) и. jsp файлы.

Ошибка MSG:

There was an unexpected error (type=Internal Server Error, status=500).
Error resolving template [feed], template might not exist or might not be accessible by any of the configured Template Resolvers
org.thymeleaf.exceptions.TemplateInputException: Error resolving template [feed], template might not exist or might not be accessible by any of the configured Template Resolvers

Project Structre введите описание изображения здесь

WebConfig.class

@Configuration
public class WebConfig implements WebMvcConfigurer {

    public static final String RESOLVER_PREFIX = "/WEB-INF/jsp/";
    public static final String RESOLVER_SUFFIX = ".jsp";

    @Bean
    public ViewResolver viewResolver(){
        UrlBasedViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix(RESOLVER_PREFIX);
        viewResolver.setSuffix(RESOLVER_SUFFIX);
        return viewResolver;
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("home");
        registry.addViewController("home").setViewName("home");
    }

}

Controller.class

@Slf4j
@org.springframework.stereotype.Controller
public class Controller {

// some code to handle hiberante 

    @GetMapping("feed")
    public String feed(){
        log.info("feed called........");
        return "feed";
    }
}

SpringAppApplication.class

@SpringBootApplication
public class SpringAppApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringAppApplication.class, args);
    }

}

В application.properties соответствующая часть:

spring.resources.static-locations=classpath:/WEB-INF/jsp/,classpath:/templates/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

фид. jsp, который не разрешается

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ngodev project</title>
</head>
    <body>
        <div align="center">
// some HTML
        </div>
    </body>
</html>

Наконец зависимости от моего пом. xml

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...