Java – data source for multi tenant applications
I am developing a multi tenant application based on Hibernate 4
Solution
To answer your questions directly, you can expose your application context through JMX and modify it programmatically The problem with this is that the changes will be temporary, that is, if you restart the server, they will not be retained
Another option is to modify the underlying XML file programmatically (assuming that you are using XML) and call refresh () in the context of the application. For example, you can create a speed template using placeholders for data sources:
<beans> ... #foreach ( $datasource in $datasources ) $datasource #end ... </beans>
Then, you pass a list of all the required data sources to velocity and generate an updated datasource - context xml
But as other users have pointed out, this is not a good idea. It is best to use partitioning or other methods