【问题标题】:Betamax with Spring Boot throws Illegal use of nonvirtual function call带有 Spring Boot 的 Betamax 引发非法使用非虚拟函数调用
【发布时间】:2015-10-06 18:16:26
【问题描述】:

我正在尝试使用 Betamax 在 Groovy 中使用 Spock 设置一个简单的测试:

class BetaMaxSpockTest extends Specification {

    @Rule
    public Recorder recorder = new Recorder()

    @Betamax(tape = "some_tape")
    def 'You shall pass'() {
        expect:
        true
    }
}

我也在使用 Spring Boot,所以我在 pom.xml 中有 spring-boot-starter-parent 作为我的父级:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.6.RELEASE</version>
</parent>

当我运行上面的测试时,我收到了这个错误:

java.lang.VerifyError: (class: co/freeside/betamax/proxy/jetty/BetamaxProxy, method: super$3$getBean signature: (Ljava/lang/Class;)Ljava/lang/Object;) Illegal use of nonvirtual function call
at java.lang.Class.forName(Class.java:264)
at co.freeside.betamax.proxy.jetty.ProxyServer.start(ProxyServer.groovy:47)
at co.freeside.betamax.Recorder.startProxy(Recorder.groovy:198)
at co.freeside.betamax.Recorder.withTape(Recorder.groovy:167)
at co.freeside.betamax.Recorder$1.evaluate(Recorder.groovy:185)
at org.spockframework.runtime.extension.builtin.MethodRuleInterceptor.intercept(MethodRuleInterceptor.java:40)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:84)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:138)
at org.spockframework.util.ReflectionUtil.invokeMethod

如果路径上没有 Spring Boot,它可以正常工作。看起来像一些版本问题。有人遇到过类似问题吗?

我的完整 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.6.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <!--plugins versions-->
        <maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
        <!--settings-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!--Spring Boot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--Spock Testing-->
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <scope>test</scope>
        </dependency>
        <!--Groovy Testing-->
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <scope>test</scope>
        </dependency>
        <!--Betamax Http Mocks-->
        <dependency>
            <groupId>co.freeside</groupId>
            <artifactId>betamax</artifactId>
            <version>1.1.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
        </plugins>

        <pluginManagement>
            <--...-->
        </pluginManagement>
    </build>
</project>

【问题讨论】:

  • @tim_yates 1.8
  • 是的,我可以看到....但是 1.8 的哪个版本? u60?
  • Java 版本 - build 1.8.0_45-b14 @Opal,我没有使用 gradle。
  • 你试过最新的jdk吗?我知道在 1.8 的某些版本中存在验证错误
  • 将 Java 更新为(内部版本 1.8.0_60-b27),但没有任何改变..

标签: groovy spring-boot spock betamax


【解决方案1】:

您可以采取一些措施来解决此问题。首先是您可以编写有问题的代码@CompileStatic(可能是您的情况下的规范),这通常可以解决问题,但这并不总是可取的(并且并不总是有效)。

您可以做的另一件事是将-Xverify:none 添加到您的java 命令行选项中(无论您在哪里为您的环境指定它们)。这将关闭验证,这是导致错误的原因。

根据我最初遇到此问题时所读到的内容,他们计划在下一个 Java 版本中默认关闭验证。这通常发生在 Groovy 或其他在后台进行大量字节码操作的库中(asm 是另一个)。

【讨论】:

    【解决方案2】:

    我找到了解决方案。问题出在 jetty 和 httpclient 的错误版本中。 BetaMax 需要下面显示的版本,而 Spring 的父 pom 声明了更新的版本。

    将这两行添加到我的 pom.xml 中的属性解决了这个问题:

    <jetty.version>7.3.1.v20110307</jetty.version>
    <httpclient.version>4.2.1</httpclient.version>
    

    无论如何,谢谢你的帮助!

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2020-07-02
      • 2013-01-19
      • 2012-02-06
      • 2014-01-04
      • 1970-01-01
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      相关资源
      最近更新 更多