Java – accessing property files in spring expression language
•
Java
I created a simple web application using spring boot with thymeleaf I use application Properties file as configuration What I want to do is add new attributes such as name and version to the file and access the value of thymeleaf
I have been able to do this by creating a new javaconfiguration class and exposing a spring bean:
@Configuration public class ApplicationConfiguration { @Value("${name}") private String name; @Bean public String name() { return name; } }
I can use thymeleaf to display it in the template as follows:
<span th:text="${@name}"></span>
It seems too long and complicated for me What is the more elegant way to achieve this goal?
If possible, I want to avoid using XML configuration
Solution
You can get it through the environment For example:
${@environment.getProperty('name')}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码