aspose file tools*
The moose likes Spring and the fly likes Data Source problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Data Source problems " Watch "Data Source problems " New topic
Author

Data Source problems

Denis Viktorov
Greenhorn

Joined: Oct 29, 2012
Posts: 3
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

Joined: May 26, 2003
Posts: 31054
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Denis Viktorov
Greenhorn

Joined: Oct 29, 2012
Posts: 3
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

Joined: Oct 29, 2012
Posts: 3
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Data Source problems