Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change spring datasource settings at runtime

Tags:

java

spring

I have a spring web application which a user can deploy on their own servers. Once the application is running, the adminstrator can set the database URL and credentials from the front end, and there is no default one set up. I do not know how to do this with spring / hibernate, as my datasource is wired in once the LocalSessionFacytoryBean is created in the initialisation of my spring container.

like image 851
mogronalol Avatar asked Jun 19 '26 18:06

mogronalol


2 Answers

If your application server supports it and its not to complicated for your users you could use JNDI datasources. They are configurable over the application server, however its not the same as changing them at runtime.

like image 122
Udo Held Avatar answered Jun 21 '26 06:06

Udo Held


You can build a SessionFactory object with a custom data source at runtime, and use that insted. Nothing stops you from that.

like image 30
Bozho Avatar answered Jun 21 '26 06:06

Bozho



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!