spring - 没有这样的属性 : org. codehaus.grails.INCLUDED_JS_LIBRARIES

标签 spring tomcat grails phantomjs grails-2.2

要求

我正在尝试在基于功能测试阶段的自定义测试阶段运行我的 JavaScript 测试。基本上它需要:

  • 启动嵌入式 Tomcat
  • 打开 Controller
  • 检查执行测试的结果

我做了什么

首先,我基于这个 post 创建了自定义测试阶段.所以我的 _Events.groovy 看起来像

includeTargets << new File("${basedir}/scripts/_RunJavaScriptUiTests.groovy")

eventConfigureTomcat = { tomcat ->
  tomcat.connector.setAttribute("compression", "on")
  tomcat.connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,application/javascript")
  tomcat.connector.port = serverPort
}

eventAllTestsStart = {
  phasesToRun << "uijs"
}

uijsTests = ["uijs"]

uijsTestPhasePreparation = { 
  functionalTestPhasePreparation()
}

uijsTestPhaseCleanUp = { 
  functionalTestPhaseCleanUp()
}
eventTestPhaseEnd = { phase ->
  if( phase == "uijs" ) {
    runJavaScriptUiTests()
  }
}

接下来,我决定使用 PhantomJS打开我的页面并分析执行的测试。所以我在 RunJavaScriptUiTests.groovy 脚本中使用了它

target(runJavaScriptUiTests:"Running Siesta tests") {

    event("StatusUpdate", ["Siesta test phase..."])

    //this is the script that evaluates the result of the tests
    File script = new File("web-app/js/siesta/siesta-phantomjs-runner.js")

    String home = System.getenv("PHANTOMJS_HOME")
    if(!home) {
        throw new RuntimeException("PHANTOMJS_HOME must be set.")
    }

    String executable = "${home}bin${File.separator}phantomjs"
    String port = System.getProperty("server.port","8080")
    String url = "http://localhost:$port/insoft-ext-ui/siesta" //url of my tests

    println "Running Phantomjs ${executable} ${script.absolutePath} "

    try {
        ant.exec(executable: executable, outputproperty: "cmdOut", failonerror: 'true', errorproperty: "cmdErr") {
            arg(value: script.absolutePath)
            arg(value: url)
        }
        }catch(e) {
        println "ERROR: $e"
        throw e
    }

    try {

        String output = "${ant.project.properties.cmdOut}"
        println output

        }catch(e) {
        event("StatusError",["Exception $e"])
    }

}

我可以看到 functionalTestPhasePreparation 正在运行,因为这会正确启动我的应用程序。我还可以看到 phantomjs 命令在打印时是正确的:

Running: /desenv/phantomjs-1.9.2/bin/phantomjs /desenv/java/projetos/insoft-ext-ui/web-app/js/siesta/siesta-phantomjs-runner.js http://localhost:8080/insoft-ext-ui/siesta

但这给了我groovy.lang.MissingPropertyException

groovy.lang.MissingPropertyException: No such property: org.codehaus.grails.INCLUDED_JS_LIBRARIES for class: org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:273)
    at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at org.codehaus.groovy.grails.web.filters.JavascriptLibraryFilters$_closure1_closure2_closure3.doCall(JavascriptLibraryFilters.groovy:27)
    at org.codehaus.groovy.grails.web.filters.JavascriptLibraryFilters$_closure1_closure2_closure3.doCall(JavascriptLibraryFilters.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

有关完整的 Stacktrace,请参阅 here .

有趣的是,如果我只是这样做

grails test run-app
phantomjs /desenv/java/projetos/insoft-ext-ui/web-app/js/siesta/siesta-phantomjs-runner.js http://localhost:8080/insoft-ext-ui/siesta

脚本有效,我没有遇到任何异常。

问题

为什么会抛出 MissingPropertyException?我查看了 JavascriptLibraryFilters 并没有找到它的原因。

编辑

关于Tomcat

我正在使用 Grails 附带的嵌入式 Tomcat,但在 _Events.groovy 中启用了压缩:

eventConfigureTomcat = { tomcat ->
    tomcat.connector.setAttribute("compression", "on")
    tomcat.connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,application/javascript")
    tomcat.connector.port = serverPort
}

最佳答案

我没有直接的解决方案,但我可以帮助您研究这个问题。

您的问题的根源显然是 org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper,它在您的 Tomcat 环境中应用,这解释了为什么您的代码可以独立运行。

Stack Overflow 上还存在涉及同一 Spring 类的其他问题。其中大部分是关于不正确的多部分请求处理的问题。 这会让我相信 PhantomJS 正在进行多部分调用,而没有适合您的环境的转换或接口(interface)。我怀疑可能需要更改您的 Tomcat 或 Grails 配置。

以下是我提到的几个 SO 问题:

这是 Grails/CXF 上的潜在相关错误:

  • > Spring Security bug , 指的是 CXF bug ,上面写着“要在 CXF 上启用 MTOM,您必须通过在 Config.groovy 中设置选项 grails.web.disable.multipart=true 来禁用 Grails 的多部分处理>”

请提供有关您的 Tomcat/Grails 设置的任何详细信息和/或确认您已调查这些潜在的问题路径,以便我们对它们进行折扣。

希望这个答案能为您或其他人指明正确的方向,从而找到合适的解决方案。

关于spring - 没有这样的属性 : org. codehaus.grails.INCLUDED_JS_LIBRARIES,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18959329/

相关文章:

java - 如何在没有kafka服务器的情况下运行spring boot

tomcat 网址和 robots.txt

java - 文件重新加载后台线程与基于请求

image - 如何在编辑 View 上更新图像?

Grails 数据库迁移插件

Spring 安全 : always redirect logged in users to a page

Android Spring文件上传OutofMemory

java - 我的 Controller bean (Spring-MVC) 中未处理 Autowiring bean

java - 在部署 Web 服务时运行启动方法

grails - groovy ArrayList 强制转换(注意 : appears to be a bug with the runtime error line identification, 不是 ArrayList 强制转换)