Seed data for grails application

女生的网名这么多〃 提交于 2019-12-06 11:29:47

Another answer would be to leverage grails run-script. This would allow you to move what you might put in bootstrap and keep it where you want on your file system (possibly outside of the codebase). Similarly, you could install the console plugin and load code through that on a running application.

Depending on your data needs, check out the great build-test-data plugin as well.

I'm using the Fixtures plugin to load test/initial data, it works for me.

http://www.grails.org/plugin/fixtures

look into SeedMe plugin: https://github.com/bertramdev/seed-me

seed = {
    author(meta:[key:'name'], name: 'David', description: 'Author Bio Here')
}

One way I have generated seed data is using a service. I created a class, lets call it SeederService. I can inject this service in the Bootstrap.groovy and call whatever method I would want.

The beauty of SeederService is that you can also use the same service in your unit-tests. Simply inject the service class in your unit test and generate your seed data.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!