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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23789271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 01:13:04  来源:igfitidea点击:

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

javaspringmavenjunit

提问by JavaBee

Am very new to spring and JUnit. Am trying to run a simple JUnit test case for spring service class, but it fails and I get this exception.I didnt write any test yet, but trying to run through before implementing. Using tomcat v7.0. And I dont think have any spring conflicting versions. Please help.

我对 spring 和 JUnit 很陌生。我正在尝试为 spring 服务类运行一个简单的 JUnit 测试用例,但它失败了,我得到了这个异常。我还没有写任何测试,但在实现之前尝试运行。使用 tomcat v7.0。而且我认为没有任何与弹簧冲突的版本。请帮忙。

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)Z
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:126)
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:96)
at org.springframework.test.context.ContextLoaderUtils.resolveActiveProfiles(ContextLoaderUtils.java:499)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:722)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:656)
at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:93)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:119)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:120)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Where else do i need to check, if there are any conflicting spring jars in my project? And my pom.xml file is:

我还需要检查哪里,我的项目中是否有任何冲突的弹簧罐?我的 pom.xml 文件是:

<dependencies>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.0.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>3.1.4.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    <version>1.5.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons-core</artifactId>
    <version>1.4.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-dao</artifactId>
    <version>2.0.8</version>
</dependency>
<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>10.10.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbyclient</artifactId>
    <version>10.10.1.1</version>
</dependency>         
<dependency>
    <groupId>commons-pool</groupId>
    <artifactId>commons-pool</artifactId>
    <version>1.6</version>
</dependency>
<dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>1.0.0.RELEASE</version>
</dependency>

采纳答案by Oleg Estekhin

That method appeared in that commit, which seems to be 4.0.3+. Just update spring dependencies to the latest version.

该方法出现在那个 commit 中,似乎是 4.0.3+。只需将 spring 依赖项更新到最新版本即可。

回答by M. Deinum

The problem is that you are mixing different versions of Spring, you are mixing (2.0.8, 3.1.4 and 4.0.2) in your project. That is trouble waiting to happen.

问题是您正在混合不同版本的 Spring,在您的项目中混合(2.0.8、3.1.4 和 4.0.2)。这是等待发生的麻烦。

To prevent these kind of things there is now a so called "bill of materials" POMwhich you can import.

为了防止这些事情,现在有一个所谓的“物料清单”POM,您可以导入它。

You need to add a dependencyManagement section to import the bom.

您需要添加一个dependencyManagement 部分来导入bom。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.0.5.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Now in your dependencies you can remove the version and replace spring-daowith spring-orm. Added benefit is that all your spring-* dependencies will now be managed to the latest release and you only have a single location for your version number.

现在在您的依赖项中,您可以删除版本并替换spring-daospring-orm. 额外的好处是,您所有的 spring-* 依赖项现在都将管理到最新版本,并且您的版本号只有一个位置。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
</dependency>

You could apply the same trick for Spring Data as that also has a bom.

您可以对 Spring Data 应用相同的技巧,因为它也有一个bom

回答by Sireesh Yarlagadda

Replace your old jars with new one's based on the spring-framework-bom.LATEST.VERSION.pom file.

根据 spring-framework-bom.LATEST.VERSION.pom 文件用新的 jar 替换旧的 jar。

That way, i had resolved my issue.

这样,我就解决了我的问题。

回答by user1689784

I just deleted the target folder in my maven project and rebuilt the war and this problem vanished.

我刚刚删除了我的 Maven 项目中的目标文件夹并重建了War,这个问题就消失了。