Grails Fixtures:grails run-app工作,但是mvn grails:run-app not

时间:2013-04-19 12:47:46

标签: maven grails fixtures

我已经安装了Grails Fixtures插件(http://www.grails.org/plugin/fixtures),用于将一些初始数据加载到我的数据库中以用于开发和测试环境。我也使用Grails与Maven集成。

我已将数据加载代码添加到BootStrap.groovy:

import grails.util.Environment

class BootStrap {
    def fixtureLoader

    def init = { servletContext ->

        if (Environment.current == Environment.DEVELOPMENT || Environment.current == Environment.TEST) {
            //def fixtureLoader = new FixtureLoader(grailsApplication)
            fixtureLoader.load("init")
        }
    }

}

当我使用“grail run-app”运行我的Grails应用程序时,它运行得很好,但是如果我使用Maven Grails命令“mvn grails:run-app -Dgrails.env = development”那么它就不起作用了。它抛出以下错误:

Error executing bootstraps; nested exception is java.lang.NullPointerException: Cannot invoke method load() on null object

如果我使用Maven Grails命令“mvn grails:run-app”,似乎没有正确初始化“fixtureLoader”bean。

你知道吗?或者它可能是一个错误......

1 个答案:

答案 0 :(得分:2)

dependency而不是pom.xml中将其添加为BuildConfig.groovy。 Maven查看pom来解决依赖关系(在本例中是一个插件)。

<dependency>
  <groupId>org.grails.plugins</groupId>
  <artifactId>fixtures</artifactId>
  <version>1.0.7</version>
  <scope>runtime</scope>
  <type>zip</type>
</dependency>

注意:范围runtime也可以在test范围内提供工件。

相关问题