This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Source problems

 
Denis Viktorov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I have some problems with data source.
In that code:



PostgreSQL ignores username (and only username), in spite that it is set in property file:



It tries to connect via default systems username. Any ideas?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Denis,
Welcome to CodeRanch!

Let's first try to isolate it to a database vs Spring issue. Can see whether ${userName} is injected properly in XML? One way to do that is to create a "DenisTest" object and inject it there.
 
Denis Viktorov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for answer, Jeanne.

I found the problem. My config doesn't inject property when it names 'username'.
I changed name of property to 'pgUsername' and now it works perfectly.

And now I have another question: can somebody explain me why property with name 'username' don't work in my situation?

(sorry for bad English)
 
Denis Viktorov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, i understand the problem.

Spring 3.1 by default loads not only my properties, but also environment vars/props.

In my situations Spring loads windows environment variables and among them was 'username' variable, which overrides my 'username' property.


 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Denis Viktorov wrote:Okay, i understand the problem.

Spring 3.1 by default loads not only my properties, but also environment vars/props.

In my situations Spring loads windows environment variables and among them was 'username' variable, which overrides my 'username' property.




Yeah that is a funny gotcha that sometimes happens. The properties loader for context, was PropertyPlaceholderConfig. It will by default first look in the .properties file, then go to System.getProperty(), then look at OS environment variables, and use the first one it finds. That is by default. You can change that, you can flip the order, or you can tell it to just use the .properties file and look no further. Those are properties of the class that you can set in your configuration.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic