ec3
ec3

Reputation: 65

best way for javascript to access values from properties file in spring application

What's the current best way for javascript to access values that are set in an external properties file?

For ex. I want to set up a time out redirect with the session time configurable via a properties file. Is there an obvious way to do this that I'm missing?

I'm using spring boot with thymeleaf.

Upvotes: 5

Views: 5032

Answers (1)

Tiit
Tiit

Reputation: 185

You could inline Javascript code into your HTML using th:inline.

Consider the following:

<script th:inline="javascript">
    var timeout = [[${app.timeout}]];
</script>

You'll have to create an class for the application's properties with getters and setters for the properties you'd like to access using the Thymeleaf's ${property} syntax.

Upvotes: 2

Related Questions