Update database settings in properties file in Spring

后端 未结 2 1904
醉话见心
醉话见心 2021-01-24 14:57

I am new to spring I am trying to create a Database Manager page which shows the database details on page load and updates the database settings when the user press submit

2条回答
  •  春和景丽
    2021-01-24 15:14

    You need to refresh your Application context and get the bean DriverManagerDataSource again in order to reflect the changes written to propertie files.

    context.refresh();
    DriverManagerDataSource databaseSource = (DriverManagerDataSource)context.getBean("dataSource");
    databaseSource.getUsername();
    

    Tip for getting File object of your resource:

        URI a = getClass().getResource("/com/smartcall/bundle/database.properties").toURI();
        File file = new File(a);
    

    You will not need to decode the path, i.e. replacing %20 with " ". Referrence

提交回复
热议问题