Question

I'm having problems getting Grails 2.3.6 to load fixtures during bootstrapping.

TRYING TO LOAD DATA THROWS A NULL POINTER

This the the code I tried to use:

class BootStrap {
    def fixtureLoader
    def init = { ServletContext ctx ->
        environments {
            ...
            development {
                fixtureLoader.load("developmentTinySanityCheckData")
            }
        }
    }
    ...

My project is in ~/grails-2.3.6-workspace/imca2 So I expect the above to load developmentTinySanityCheckData.groovy from ~/grails-2.3.6-workspace/imca2/fixtures

That file definitely exists and is readable:

ls -lt ~/grails-2.3.6-workspace/imca2/fixtures
-rw-r--r-- 1 nick nick    83 2014-03-16 19:32 developmentTinySanityCheckData.groovy

And contains this minimal data:

fixture {
    DoctorDecisionMakerType(com.ubergen.DecisionMakerType) {
        code = "Doctor"
    }
}

But the load fails with GrailsContextLoader NullPointerException: Cannot invoke load() on null object

[localhost-startStop-1] ERROR context.GrailsContextLoader  - Error initializing the application: Cannot invoke method load() on null object
java.lang.NullPointerException: Cannot invoke method load() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
...
at BootStrap$_closure1_closure3_closure6.call(BootStrap.groovy)
at groovy.lang.Closure.call(Closure.java:405)
at BootStrap$_closure1_closure3_closure6.call(BootStrap.groovy)
...

CANT INJECT FIXTURELOADER?

I assumed the null object meant the fixture loader was not being instantiated; perhaps its not getting created by the dependency injector? I don't know if this is correct.

I tried to force the fixtureLoader to exist with:

class BootStrap {
    def fixtureLoader
    def init = { ServletContext ctx ->
        fixtureLoader = ctx.getBean('fixtureLoader'); // INJECT LOADER
        environments {
            ...
            development {
                fixtureLoader.load("developmentTinySanityCheckData")
            }
        }
    }
    ...

But got - No signature of getBean() is applicable for argument [fixtureLoader]

ERROR context.GrailsContextLoader  - Error initializing the application: No signature of method: org.apache.catalina.core.ApplicationContextFacade.getBean() is applicable for argument types: (java.lang.String) values: [fixtureLoader]

Versions:

ubuntu 10.04
eclipse / SpringToolSuite 3.4.0
grails 2.3.6
groovy 2.1.9 (for both project and workspace)
grails plugins:
    build-test-data 2.1.2
    fixtures 1.2
Was it helpful?

Solution

My original problem was that trying to call load on the fixtureLoader threw a null pointer. It appeared the fixtureLoader was unavailable, at least in development mode.

On checking in BuildConfig.groovy I found

plugins {
    ...
    compile ":build-test-data:2.1.2"
    test ":fixtures:1.2"
}

which presumably means the fixture loader is only created and available to use when the execution mode is test.

I corrected this to:

plugins {
    ...
    compile ":build-test-data:2.1.2"
    compile ":fixtures:1.2"
}

and the loader was created and worked in development mode too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top