Thursday, May 02, 2013

Grails Fixtures in Bootstrap.. the missing pieces

One nifty way to load in a lot of data into either development or perhaps even production instances of Grails apps is the Fixtures Plugin. You can more easily define loads of data and multiple relationships with this plugin. This plugin is designed to be used for integration test data, but as noted here, nothing should prevent you from loading it in your Grails bootstrap step. However, I ran into curious errors such as "Fixture does not have bean". For my future self, here's the solutions to avoid incorrect assumptions:

  • In the BootStrap.groovy file, define the service fixtureLoader within the BootStrap class (def fixtureLoader).
  • All fixtures must be in a closure titled "fixture {}"
  • Each domain class needs importing at the top of each fixture file. This is the resolution to the bean error noted above.

No comments: