Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
@RunWith(SpringJUnit4ClassRunner.class)导致java.lang.NoSuchMethodError_Java_Spring_Maven_Junit4 - Fatal编程技术网

@RunWith(SpringJUnit4ClassRunner.class)导致java.lang.NoSuchMethodError

@RunWith(SpringJUnit4ClassRunner.class)导致java.lang.NoSuchMethodError,java,spring,maven,junit4,Java,Spring,Maven,Junit4,我尝试运行rest控制器跟踪的单元测试 对于这个类,我总是得到错误: java.lang.NoSuchMethodError:org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/annotation;) 我发现有人也有类似的错误,因为他很少使用spring版本() 但我认为我使用最新的库,这不是问题。为了可靠性,我附加了我的“mvn依赖关系:

我尝试运行rest控制器跟踪的单元测试

对于这个类,我总是得到错误:

java.lang.NoSuchMethodError:org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/annotation;)

我发现有人也有类似的错误,因为他很少使用spring版本()

但我认为我使用最新的库,这不是问题。为了可靠性,我附加了我的“mvn依赖关系:树”结果

[INFO] +- org.springframework.boot:spring-boot-starter-            web:jar:1.2.7.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.2.7.RELEASE:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] |  |  |  +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] |  |  |  \- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  |  |     \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.14:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.6:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.6:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.6:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-web:jar:4.1.8.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.1.8.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.2.7.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.2.7.RELEASE:compile
[INFO] |  |  +- org.aspectj:aspectjrt:jar:1.8.7:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.7:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.2.7.RELEASE:compile
[INFO] |  |  \- org.apache.tomcat:tomcat-jdbc:jar:8.0.28:compile
[INFO] |  |     \- org.apache.tomcat:tomcat-juli:jar:8.0.28:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework:spring-orm:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.7.4.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.9.4.RELEASE:compile
[INFO] |  |  +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.1.8.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.2.7.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.1.8.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:3.2.8.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework.security:spring-security-web:jar:3.2.8.RELEASE:compile
[INFO] |  \- org.springframework:spring-aop:jar:4.1.8.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.1.8.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.1.8.RELEASE:compile
[INFO] +- com.h2database:h2:jar:1.4.190:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.2.7.RELEASE:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.28:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.28:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.28:compile
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.28:compile
[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.7.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:3.2.8.RELEASE:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.6:compile
[INFO] |  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |     \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- org.springframework:spring-test:jar:4.1.8.RELEASE:test
[INFO] \- junit:junit:jar:4.12:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test
编辑: 随附的pom文件:

<?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>team.pocket.lublin</groupId>
    <artifactId>pocket-lublin</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

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

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>

4.0.0
卢布林队
袖珍卢布林
1.0.0-SNAPSHOT
1.8
org.springframework.boot
spring启动程序父级
1.2.7.发布
战争
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧启动安全
org.springframework
SpringJDBC
com.h2数据库
氢
org.springframework.boot
弹簧启动机tomcat
org.springframework.security.oauth
spring-security-oauth2
2.0.7.1发布
org.springframework
弹簧试验
测试
朱尼特
朱尼特
4.12
测试
org.springframework.boot
springbootmaven插件
春假
https://repo.spring.io/libs-release
春假
https://repo.spring.io/libs-release

您何时收到此错误?在您的IDE中或从命令行运行时?从IDE(InteliJ Idea 14社区)运行测试后,确保您只有maven依赖项,并且没有自己在类路径中添加依赖项/库。您可以发布POM吗?(这样我们可以更容易地重现错误)戴纳姆先生,非常感谢!看起来InteliJ IDEA可以记住maven的旧依赖项,在删除和重新导入之后,测试运行不会出现问题。什么时候会出现此错误?在您的IDE中或从命令行运行时?从IDE(InteliJ Idea 14社区)运行测试后,确保您只有maven依赖项,并且没有自己在类路径中添加依赖项/库。您可以发布POM吗?(这样我们可以更容易地重现错误)戴纳姆先生,非常感谢!看起来InteliJ IDEA可以记住maven的旧依赖项,在删除和重新导入之后,测试运行不会出现问题。
<?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>team.pocket.lublin</groupId>
    <artifactId>pocket-lublin</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.0.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

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

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>
</project>