Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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")
like image 654
Himanshu Yadav Avatar asked Jan 25 '26 17:01

Himanshu Yadav


2 Answers

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.

like image 137
Leland Barton Avatar answered Jan 28 '26 10:01

Leland Barton


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

like image 31
jaknichan Avatar answered Jan 28 '26 11:01

jaknichan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!