使用Spring Boot的Betamax抛出非法使用非虚拟函数的调用 [英] Betamax with Spring Boot throws Illegal use of nonvirtual function call

查看:81
本文介绍了使用Spring Boot的Betamax抛出非法使用非虚拟函数的调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to setup a simple test in Groovy with Spock using Betamax:

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作为我的父母:

I'm also using Spring Boot so I have spring-boot-starter-parent as my parent in pom.xml:

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

当我通过测试时,出现此错误:

When I run above test I'm getting this error:

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的情况下,它可以正常工作.看起来有些版本问题.有人遇到过类似的问题吗?

Without Spring Boot on path it works fine. Looks like some versions problem. Anyone had similar issue?

我的完整pom.xml:

My full 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>

推荐答案

我找到了解决方案.问题出在码头和httpclient的版本错误.BetaMax需要下面显示的版本,而Spring的父pom声明了许多新版本.

I have found the solution. The problem was in wrong versions of jetty and httpclient. BetaMax requires versions shown below, while Spring's parent pom declares much newer versions.

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

Adding this two lines to properties in my pom.xml solved the issue:

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

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

Anyway, thanks for your help!

这篇关于使用Spring Boot的Betamax抛出非法使用非虚拟函数的调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆