java - How to dynamically change Spring JdbcTemplate DataSource? -
i have config file default settings jdbc connection.
is there option edit default connection details once application running? after beans has been created (edit connection details in controller).
scenario:
- user starts application, , can edit connection details going localhost:8080/myapp/db/edit
- fills in connection details , saves new database details
this should find existing connections, update connection details , reinstantiate beans.
you can try removing beans spring container , re initiating them.
demo demo = getbean(context); configurablelistablebeanfactory configurablelistablebeanfactory = context .getbeanfactory(); beandefinitionregistry beandefinitionregistry = (beandefinitionregistry) configurablelistablebeanfactory; // removing bean container beandefinitionregistry.removebeandefinition("demo"); // trying obtains bean again container. throw null demo = getbean(context); //demo object null here // creating , registering bean container beandefinition beandefinition = new rootbeandefinition(demo.class); beandefinition.setattribute("name", "name"); beandefinitionregistry.registerbeandefinition("demo", beandefinition); context.refresh(); //obtaining container again demo = getbean(context);
Comments
Post a Comment