Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Spring Boot: Publish Thymeleaf template without restarting the server

Is there a way to publish Thymeleaf template without running and building the war file?
This is how my gradle file looks:

apply plugin: 'war'

war {
    baseName = 'bootBlog'
    version =  '0.1.0'
}


repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://repo.spring.io/libs-release" }
}

configurations {
    providedRuntime
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-starter-data-mongodb")
    compile("org.springframework.boot:spring-boot-starter-actuator")
    testCompile("junit:junit")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")

Upvotes: 3

Views: 5907

Answers (2)

jaknichan
jaknichan

Reputation: 41

If you still want to use Springboot rather than Gradle, you can add two more properties in your properties file :

  • project.base-dir (it is not a springboot known property, see it as a variable to define the path to your project)
  • spring.thymeleaf.prefix

To summerize, your properties file should contain these properties :

  • project.base-dir=file:///path/to/your/project/base/dir

  • spring.thymeleaf.prefix=${project.base-dir}/src/main/resources/templates/

  • spring.thymeleaf.cache=false

Upvotes: 1

yxre
yxre

Reputation: 3704

The way thymeleaf works is by caching all thymeleaf templates as the server is booting up. This is the reason you are not getting the latest template. To stop the caching, there is an application setting that is in the application.properties called:

 spring.thymeleaf.cache=false

Turning this off prevents caching and allows the templates to be refreshed without restarting the server.

Once you entered in the configuration, stop the server and start it with gradle bootRun. From now on you will be able to get the latest thymeleaf templates without a refresh.

Upvotes: 10

Related Questions