0

I'm working on a web application that uses spring boot, JavaScript and REST API to interact with the database. I have a jar file where I configured several environment variables that store urls and parts of urls. In Spring Boot controller I used the following line to grab an environment variable:

@Resource 
private Environment environment;
String prefix = environment.getProperty("rest.resource.name");

Is there something equivalent I could use with JavaScript to perform this operation?

1
  • 2
    No, client side JS can't interact with the underlying system. You need to ask the server to send it to you Commented Jun 7, 2016 at 14:57

1 Answer 1

2

You can't do that directly, however, you could use a templating language (Thymeleaf, Velocity or even JSPs) and put a <script> block inside your template.

An example with Thymeleaf:

<script th:inline="javascript">
  /*<![CDATA[*/
    var myProperty = /*[[${@environment.getProperty('rest.resource.name')}]]*/ null;   
</script>

Now you can use myProperty inside your JavaScript code (at least if you put your JavaScript sources below this script block in your HTML page).

With JSP you can do a similar thing:

<spring:eval expression="@environment.getProperty('rest.resource.name')" var="myProperty"/>
<script type="text/javascript">
    var myProperty = '${myProperty}';
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.