i have bunch of data exists in separate file , trying figure out how automatically load data db when grails application starts up.
i put json file grails-app/conf/resources
, edited bootstrap.groovy
.
at top of file, injected grails application:
class bootstrap { def grailsapplication ...
and later on loaded data:
if (!cars.count()) { // add cars def filepath = "resources/carsdata.json" def text = grailsapplication.getparentcontext().getresource("classpath:$filepath").getinputstream().gettext() def json = json.parse(text) (cardata in json) { def c = new cars( name: cardata ["name"], year: cardata ["year"] ).save(failonerror: true); } }
Comments
Post a Comment