Grails 3 bootstrap - service doesn't create db entry

211 views Asked by At

I have a very simple service set up to create an entry in a Postgres table, and I use it in Bootstrap.groovy for my Grails 3 web-app.

// CompanyService
public Company createCompany(String name) {
    Company company = new Company(name: name)
    company.save()
    return company
}

// BootStrap
def init = {
    companyService.createCompany('My Company')
}

Well, at startup I cannot see My Company entry, no matter if the service is transactional or not. Instead, if using the same line for example in a controller, it works as expected. Am I missing something here?

1

There are 1 answers

1
monty_bean On

Have you called your service inside bootstrap?

class BootStrap {

   def companyService

   def init = { servletContext ->
      companyService.createCompany('My Company')
   }
}