Question

i excute the following code via grails console instead of BootStrap :

class BootStrap {
def fixtureLoader

    def init = { servletContext ->
        fixtureLoader.load("MockRecords")


    }

}

I get the following error :

java.lang.NullPointerException: Cannot invoke method load() on null object
    at Script1.run(Script1.groovy:16)
    at org.grails.plugins.console.ConsoleService.eval(ConsoleService.groovy:57)
    at org.grails.plugins.console.ConsoleService.eval(ConsoleService.groovy:37)
    at org.grails.plugins.console.ConsoleController$_closure2.doCall(ConsoleController.groovy:61)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)
undefined

How can i use console to load fixtures

Was it helpful?

Solution

More easy , Without using getBean:

ctx.fixtureLoader.load("MockRecords")

it works.

OTHER TIPS

DI(dependency injection) is done automatically in grails through the pattern CoC.

So if you copy / paste the code, the console will not inject the dependency. So it must be injected manually by calling the foctory ctx.getBean ('')

def fixtureLoader=ctx.getBean('fixtureLoader');

fixtureLoader.load("MockRecords")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top