![](/img/trans.png)
[英]How can I make my spring boot application to log in to keycloak with given username and password?
[英]Can i load username and password by file in spring boot + hibernate?
我想使用spring boot,oracle db和hibernate。 我想通过两个文件(user.txt和password.txt)加载oracle db模式的用户名和密码。 我可以使用休眠吗? 我不知道如何从用于休眠的application.properties文件中加载用户名和密码。 (spring.datasource.username =从user.txt加载,spring.datasource.password =从password.txt加载)。 用户和密码在文件中加密。
有谁知道我该怎么做?
有几种方法可以使用属性文件,而不是txt文件。 如果您愿意采用这种方法,则可以选择:
配置类中的@PorpertySources。 一个例子是
@PropertySources({ @PropertySource("/user.properties"), @PropertySource("/password.properties") }). @Configuration public configClass{ @Value("{db.user}") private String user; @Value("{db.password}") private String password; ... }
db.user和db.password必须在配置文件中定义。 使用这些数据,您可以定义数据源(您还将需要连接URL)
只需在.jar之外添加另一个application.properties,其中包括数据库信息。 参见spring docs-> https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
将application.properties放在打包的jar文件之外。 Spring Boot将在同一目录中查找属性,并且可以像访问文件位于类路径中那样访问值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.