html - Getting a value in application.properties file using javascript in spring boot - Stack Overflow

In my index.html page, a variable in the script is hard coded. I want to get it from application.proper

In my index.html page, a variable in the script is hard coded. I want to get it from application.properties file but have no idea how to. It would helpful if anyone could provide me a solution.

In my index.html page, a variable in the script is hard coded. I want to get it from application.properties file but have no idea how to. It would helpful if anyone could provide me a solution.

Share Improve this question asked Feb 19, 2015 at 6:29 Mani Pushkal SirikiMani Pushkal Siriki 611 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

I have attached the example. Hope to help.

Application

@SpringBootApplication
public class Application {

    public static void main(String... args) {
        SpringApplication.run(Application.class);
    }

}

PropertiesController

@RestController
public class PropertiesController {

    @Autowired
    private UIProperty uiProperty;

    @RequestMapping("properties")
    public UIProperty getProperties() {
        return uiProperty;
    }

}

UIProperty

@Component
@ConfigurationProperties(prefix = "ui.label")
public class UIProperty {

    private String user;
    private String password;

    public void setUser(String user) {
        this.user = user;
    }

    public String getUser() {
        return user;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }
}

application.properties

ui.label.user=user
ui.label.password=password

database.user=
database.password=

I'd create a RestController to expose ConfigurationProperties. But be sure to properly secure it as well as limit in its scope not to disclose confidential data like db access credentials.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745383510a4625338.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信