我试图让Fixtures插件适用于我的单元测试,但每次我加载数据时,我总是得到BeanCreationException
。
以下是我的规范中的setup
方法的样子:
def fixtureLoader = new FixtureLoader(grailsApplication)
def setup() {
fixtureLoader.load {
person(Person, firstName: 'Juan', lastName: 'dela Cruz')
}
}
每次我进行任何测试我都会得到:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'person': Initialization of bean failed; nested exception is java.lang.NullPointerException: Cannot invoke method getDomainClass() on null object
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:156)
at grails.spring.BeanBuilder.createApplicationContext(BeanBuilder.java:593)
at grails.plugin.fixtures.builder.FixtureBuilder.createApplicationContext(FixtureBuilder.groovy:140)
at grails.plugin.fixtures.Fixture.load(Fixture.groovy:43)
at grails.plugin.fixtures.FixtureLoader.load(FixtureLoader.groovy:50)
at demo.SampleSpec.setup(SampleSpec.groovy:16)
Caused by: java.lang.NullPointerException: Cannot invoke method getDomainClass() on null object
at grails.plugin.fixtures.builder.processor.FixtureBeanPostProcessor.getDomainClass(FixtureBeanPostProcessor.groovy:136)
at grails.plugin.fixtures.builder.processor.FixtureBeanPostProcessor.postProcessAfterInitialization(FixtureBeanPostProcessor.groovy:40)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1558)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 14 more