• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Desktop App and DataSource Connection Settings

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alaa Nassef
Ranch Hand
Posts: 471
Hibernate Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic