简体   繁体   中英

How to read a value from properties file in a javascript file

I have a spring-boot project which serves angularjs. Both the front-end and back-end code are in the same project.

In my angularjs service.js files I am calling the back-end service. I have different urls in the different properties file. I want to read them as per profile selection. I know how to read properties file in a Java class but I am not sure how to read values from properties file in a javascript file.

As shown below:

在此处输入图片说明

Some options:

  1. create a separate config.json for your angular APP (manage it manually).

  2. use maven resource plugin to filter placeholders for your config.json file (automated). Eg read in one place and substitute in another (but I don't like this way).

  3. Or create an API to return data from from your properties file as JSON. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM