Answer the question
In order to leave comments, you need to log in
How to pass parameter from properties in Spring Boot to js file?
Hello!
There is a need to pass some parameters from the properties file to the js file (js code is not inline, but a separate file and, accordingly, embedding with thymeleaf th: inline is not an option).
You need to pass the base url + application context to this js file.
For example
application.properties:
site.base.url=http://localhost:7777
server.servlet.context-path=/testApp
$('#drag-and-drop-zone').dmUploader({
url: 'backend/upload.php', // нужно провести здесь, замену без хардкодинга урла
maxFileSize: 3000000,
onDragEnter: function(){
this.addClass('active');
}
}
Answer the question
In order to leave comments, you need to log in
I'll answer my own question.
If this is a classic MVC application and, for example, the thymeleaf template engine is used, then you can access the yml || properties in the following ways:
1)
${@environment.getProperty('css.specific.name')}
2) Either using annotation @ConfigurationProperties
and in html use:
<span th:text="@foo.getBar()"></span>
Useful related link:
https://stackoverflow.com/questions/56102116/acces...
PS Using Controller || ControllerAdvice for such purposes is not welcome.
Well, if you have a REST application, then this is configured on the client side inside the js framework.
As the simplest option, you can add a simple controller on the server side, which will give you either the entire config in JSON format, or a specific value from it by name. I'm not good at writing plugins for jQuery, but I think it's possible to beat it through the plugin.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question