posted 12 years ago
Hello.
I think it would be easier to understand the problem if I wrote its context first. I have a Spring application which uses data stored in a database. The database info such as url, username and password should not be fixed. Here's what I want to achieve: after the applications starts, the user is prompted for a url of the database, username and password. The given information is used to set the properties of a datasource bean.
I did find a solution but I don't think it's in a good programming style. Here's the xml file code with the definition of the datasource bean:
The prompting for the db information takes place in the main method. Here's the code:
and the setting of the properties takes place at the construction of Zarzadca object:
This solutions works but I'm not happy with it. I know there is a possibility to point the bean to it's init method, where I could prompt for and set the properties of the db. So I was thinking about writing a class that extends the com.mchange.v2.c3p0.ComboPooledDataSource class and put an init method there. Sadly, I found out that the class is final and therefore cannot be extended. Could someone please help me solve this? I would be very thankful.
p.s. oh, and I would rather not use the property files.