【发布时间】:2021-12-31 22:23:46
【问题描述】:
我检查了类似的问题:
Spring Boot: @Value returns always null
但是,我找不到我的注释有什么问题
这是代码在 IntelliJ 中的外观 screenshot from IntelliJ
下面是这个
@Component
public class VisitMapper {
@Value("${spring.datasource.url}")
private String url;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
//more code below
我有两个 .properties 文件:application-dev.properties 和 application.properties。 活动配置文件设置为 dev。 在 application-dev.properties 我有:
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
不确定它是否重要,因为活动配置文件设置为 dev,但在 application.properties 我有:
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
总结一下-为什么密码值显示为空?
【问题讨论】:
-
你真的运行过代码吗?我怀疑它不是空的,并且您被 IDE 中的某些东西抛弃了(这可能会隐藏密码以防窥探)。
-
我在运行代码时遇到了一些问题,可能与此问题无关。应用程序启动,但是当我尝试调试和发送任何请求时,我得到了错误。
-
如果它启动它就被解决了,如前所述,您可能会被 IDE 抛出(除非您的错误与数据库相关,但这会阻止您的应用程序首先启动)。跨度>
-
感谢您的回答。但是像“隐藏”这样的消息不会比“空”来阻止窥视者更好吗?
-
您必须与 Jetbrains 的人员一起讨论这个问题。如果您的应用程序启动配置被正确读取,否则它会爆炸。
标签: spring postgresql spring-boot annotations