Spring 5.2.1.RELEASE getProperty returns "User" instead of my custom "username=..." property

52 views Asked by At

I have found out that for some reason

dataSource.setUsername(environment.getProperty("username"));

returns "User" value instead of my property username=postgres It is indicated in the HTTP 500 DB connection error

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.postgresql.util.PSQLException: FATAL: password authentication failed for user "User"

And if I debug in Intellij Idea, I see that when I execute that string, it ends up with "User" for some reason. I guess there is some collision of implementation the getProperty() method of the PropertyResolver interface. However, I could not find from where that implementation and collision comes from.

I am learning Spring framework, I watch a video course. The only difference between my and the course project is that I am using the currently latest postgres, thus, pom.xml contains the latest postgres dependency. However, if I change it to the same dependency without reinstalling the postgreSQL to the needed version - I still do not get my property working.

BUT! If I rename the property and I adjust the property name in the getProperty() method, I get it working! For instance, I used "db-username" in my db.property and it worked. Regardless of the matching of the postgreSQL versions. I don't think the DB is the case. I think there is some conflict I can not find yet in the framework. Could you please let me know what could be the reason? For example, I want to use this name on principle - the "username" property naming, so how do I find the root-root cause?

P.S.

The code is below: SpringConfig: https://pastebin.com/2n0WHnut

pom.xml https://pastebin.com/NUBtZEqR

Does not work =>

dataSource.setUsername(environment.getProperty("username"));

db.property:

driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/first_db
username=postgres
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/first_db
username=postgres
password=FooBaaaaar

Works!:

dataSource.setUsername(environment.getProperty("db-username"));

db.property:

driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/first_db
username=postgres
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/first_db
db-username=postgres
password=FooBaaaaar

I have tried to debug it using IDE and I saw that the getProperty method for sure returns in the runtime the value of "User" when I user the "username" property name in the db.property and getProperty() method.

0

There are 0 answers