I have a static webpage in my Spring boot project which has this line:
<redoc spec-url='http://localhost:8080/v2/api-docs'></redoc>
How would I make this dynamic based on the profile properties, I imagine it would be something along the line of this, but I cannot find any documentation online:
<redoc spec-url='${url}'></redoc>
CodePudding user response:
AFAIK you'll need to use a templating engine (like Thymeleaf) for this.
Basically, you add the starter to your Maven POM:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.5.5.RELEASE</version>
</dependency>
(Use the version matching your Spring Boot version)
If you just want to insert values from a properties file containing key-value pairs, the Spring Boot starter will automatically configure that.
Then you create a file messages.properties
in your resources folder and in your HTML you add this template: <span th:text="#{welcome.message}" />
which would display the value of welcome.message
in the messages.properties file.
Thymeleaf also allows more complex templates.