Problem doing Spring Boot Application Deploy

Asked

Viewed 477 times

-1

I am developing an application with Spring Boot and Thymeleaf and while trying to generate the . jar that must be run on the server, it even generates everything right, but an error occurs when trying to access the page that is on /resouces/templates/admin/home.html.

The problem is that by running the method main to move up the application in my IDE, it works fine, ie, returns me the htmls pages with Thymeleaf and cool funnel, but when I Gero the . jar with the mvn returns me the following exception:

org.thymeleaf.exceptions.Templateinputexception: Error resolving template "/admin/home", template Might not exist or Might not be accessible by any of the configured Template Resolvers

My pom.xml has this information:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<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-security</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.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
     -->

    <!-- Conexão com o Postgresql -->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1100-jdbc41</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
  • 1

    I believe the problem is where your templates are. You put them on src/main/Resources/templates?

  • Which command you executed to generate the jar?

1 answer

0

The problem is in the location of your template, see here, in particular that part:

Intellij IDEA Orders the classpath differently pending on how you run your application. Running your application in the IDE via its main method will result in a Different Ordering to when you run your application using Maven or Gradle or from its Packaged jar. This can cause Spring Boot to fail to find the templates on the classpath. If you’re affected by this problem you can reorder the classpath in the IDE to place the module’s classes and Resources first. Alternatively, you can configure the template prefix to search Every templates directory on the classpath: classpath:/templates/.*

Browser other questions tagged

You are not signed in. Login or sign up in order to post.