Работает нормально в затмении, но "Не могу найти шаблон", если запустить как jar - PullRequest
0 голосов
/ 21 сентября 2018

Программа отлично работает в Windows с IDE, но когда я выпускаю jar и запускаю Ubuntu, она не будет отображать HTML.

Src:

@Controller
@EnableAutoConfiguration
@RequestMapping("/")
public class JumanController {

    @GetMapping("/")
    public String index(Model model) {
        return "index";
    }

...

Main:

@SpringBootApplication
public class App 
{
    public static void main( String[] args )
    {
        TomcatURLStreamHandlerFactory.disable();
        SpringApplication.run(JumanController.class, args);
    }
}

HTML:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
...

pom.xml:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    ...

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>2.0.5.RELEASE</version>
        </dependency>
    </dependencies>

</project>

настройка:

spring.thymeleaf.enabled=true 
spring.thymeleaf.prefix=classpath:/resources/templates/ 

Я пытался изменитьprefix до classpath:/templates/, все еще не работает.

Предупреждение при загрузке сервера:

2018-09-21 10: 46: 47.154 WARN 4048 --- [main] ion $ DefaultTemplateResolverConfiguration: не удается найти расположение шаблона: classpath: /templates / (добавьте несколько шаблонов или проверьте конфигурацию Thymeleaf)

Ошибка при индексе доступа:

2018-09-21 10: 47: 15.253 ОШИБКА 4048 -- [nio-8080-exec-1] org.thymeleaf.TemplateEngine: [THYMELEAF] [http-nio-8080-exec-1] Шаблон обработки исключений "index": ошибка при разрешении шаблона "index", шаблон может не существовать или можетнедоступен ни одному из настроенных преобразователей шаблонов

org.thymeleaf.exceptions.TemplateInputException: ошибка при разрешении шаблона "index", шаблон может не существовать или может быть недоступен любому из настроенных преобразователей шаблонов

Шаблон dir:

src/main/resources/templates/index.html

Зачем искать путь src/main/templates/ не src/main/resources/templates/?

Мне нужен только простой Spring boot содержит один static или template страницы, и может освободитьсебе в банку.Я удалил приложение. Свойства хотят, чтобы все работало по умолчанию (AutoConfiguration), но результат тот же.

Любое предложение или демонстрационный проект hello world будет полезен ...

1 Ответ

0 голосов
/ 21 сентября 2018

Решено:

  1. изменить шаблон dir с src/main/resources/templates/ на /resources/templates/.(тот же уровень с src)

  2. установить spring.thymeleaf.prefix в classpath:/templates/

Исходный код: https://github.com/arkceajin/jumanpp-java

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...