问题
I was asked to implement a logic for having separate domains for a separate user (assuming he will have his own database) means all the domains will be mapped to different database at runtime. Sounds silly i know
How can i change the datasouce(persistence configuration file) after logIn of user while datasource
are supposed to load at startup time of application.
Is it possible somehow?
NOTE: I want to change datasource of some domain to another datasource at runtime one at a time.
回答1:
You can map multiple data sources in your DataSource.groovy
file and you can create multi talented domain classes and then you can perform any CRUD
operations among these data sources at runtime.
References
- http://www.jellyfishtechnologies.com/configure-multiple-datasources-in-grails/
- http://www.jellyfishtechnologies.com/querying-on-multiple-datasource-in-grails/
- http://grails.org/doc/2.2.1/guide/conf.html#multipleDatasources
来源:https://stackoverflow.com/questions/19930204/grails-changing-datasource-at-runtime