I have checked similiar questions:
Spring Boot: @Value returns always null
Yet, I cannot find what is wrong with my annotation
This how the code looks in IntelliJ screenshot from IntelliJ
This is whats beneath
@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
I have two .properties files: application-dev.properties and application.properties. Active profile is set to dev. In application-dev.properties I have:
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres
Not sure if it is important since active profile is set to dev, but in application.properties I have:
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
To sum up - why is password value shown as empty?
CodePudding user response:
I suspect that either Intellij hides the fields with password
in them (although <empty>
is a bit of a crappy filler) or Intellij has a hard time resolving the right property value for that field (for whatever reason).
However the fact that your application starts indicates that, at least, Spring Boot does resolve the properties correctly, else it wouldn't start and blow up. It wouldn't start either due to not being able to resolve the property or due to not being able to connect to the database.