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 badges2 Answers
Reset to default 3I 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条)