Собрал в Eclipse не большой скелет (шаблон "config") для своих проектов, которые планирую в дальнейшем размещать на каком-нибудь облачном провайдере. В Eclipse всё работает хорошо. Собрал проект с помощью Maven (меню "run" => instal) и в результате получил файл проекта с названием ConfigSpringBoot-0.0.1-SNAPSHOT.jar в папке "target". Запускаю этот jar через командную строку Windows, а в итоге получаю ошибку "Whitelabel Error Page .... (type=Internal Server Error, status=500)." Что я делаю не так?
Проект в общем-то пустой, но содержит 5 классов и 4 страницы html (для проверки Thymeleaf и взаимодействия с БД). Кроме pom.xml и одной строчки в application.properties ("spring.mvc.hiddenmethod.filter.enabled: true"), никаких дополнительных конфигурационных файлов - нет. Так выглядит последняя версия pom.xml (пробовал разные варианты Executable JAR with Maven) но ничего не помогло:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
</parent>
<groupId>com.example</groupId>
<artifactId>ConfigSpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ConfigSpringBoot</name>
<description>Config Spring Boot</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
BootMain
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Я не уверен в правильности Prefix с указанием на папку "/WEB-INF/" в бине TemplateResolver, который находится в классе BootMain.
@Bean
public SpringResourceTemplateResolver templateResolver() {
SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
templateResolver.setApplicationContext(context);
templateResolver.setPrefix("/WEB-INF/");
templateResolver.setSuffix(".html");
templateResolver.setCharacterEncoding("UTF-8");
return templateResolver;
}
В pom.xml специально добавил зависимость spring-boot-devtools (true) в надежде увидеть ошибку в браузере и сделать printStackTrace. Однако, кроме сообщения Server Error, status=500 ничего не увидел. При этом контроллер сделан таким образом, что при обращении по адресу localhost:8080 я должен получать ошибку 404 (страница не найдена). Это работает :) А при обращении по адресу http ://localhost:8080/people/index (стартовая страница проекта) я получаю status=500. Ещё раз хочу заметить, что через Eclipse всё работает. Такое недоразумение возникает толь после сборки проекта и запуска jar через cmd Windows.