aspose file tools*
The moose likes Other Application Frameworks and the fly likes Desktop App and DataSource Connection Settings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Desktop App and DataSource Connection Settings" Watch "Desktop App and DataSource Connection Settings" New topic
Author

Desktop App and DataSource Connection Settings

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I'm developing a desktop application and spring is used in the service/dao layer. Right now our database connection info is specified in the applicationContext.xml file. What I need to do is have this be specified in some user settings that I can feed to Spring. If anyone has any know-how on doing this please let me know.

Thanks.


GenRocket - Experts at Building Test Data
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

PropertyPlaceholderConfigurer. This will allow you to put the values into a .properties file
so in the configuration, still in a separate xml file with using <import> but set properties like <property name="URL" value="${datasource.url}" where datasource.url is defined in the .properties file.

So in your UI of user settings, when they save it, it would write to the .properties file. Now here is the thing. Things like Datasources are immutable, so you can't change it on the fly. You would have to have code that closed the current ApplicationContext and create a new one, not really a clean solution.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 467
Originally posted by Mark Spritzler:
Things like Datasources are immutable, so you can't change it on the fly. You would have to have code that closed the current ApplicationContext and create a new one, not really a clean solution.


I agree that it's not a clean solution, but it makes things more dynamic. A better (and a little bit cleaner) solution is to make your datasource bean non singleton, and to reload it with the new parameters using the applicationContext.getBean() method. Of course this is not the cleanest solution ever.

If what you need is to specify the location of the database at the time of installation of the application, then I totally agree with Mark's first solution.


Visit my blog: http://jnassef.blogspot.com/
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Mark, I use your solution in web apps all the time. I didn't think about how that would carry over to the desktop world so I am glad it is something I am familiar with. As far as it not being clean, it's not that bad.

Assuming a different database has different data my solution regardless was going be "You need to restart the application for these changes to take affect" anyway.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Desktop App and DataSource Connection Settings