Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
Java Spring 4.1.7+;JUnit4.12从eclipse执行时不工作_Java_Eclipse_Spring_Maven_Junit - Fatal编程技术网

Java Spring 4.1.7+;JUnit4.12从eclipse执行时不工作

Java Spring 4.1.7+;JUnit4.12从eclipse执行时不工作,java,eclipse,spring,maven,junit,Java,Eclipse,Spring,Maven,Junit,我只是尝试在spring应用程序中实现单元测试,并在eclipse中执行junit测试时获得以下异常 java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)Z at org.springframework.test.util.MetaAnnotationU

我只是尝试在spring应用程序中实现单元测试,并在eclipse中执行junit测试时获得以下异常

java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.isInJavaLangAnnotationPackage(Ljava/lang/annotation/Annotation;)Z
    at org.springframework.test.util.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:117)
    at org.springframework.test.util.MetaAnnotationUtils.findAnnotationDescriptor(MetaAnnotationUtils.java:88)
    at org.springframework.test.context.support.ActiveProfilesUtils.resolveActiveProfiles(ActiveProfilesUtils.java:80)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:367)
    at org.springframework.test.context.support.AbstractTestContextBootstrapper.buildMergedContextConfiguration(AbstractTestContextBootstrapper.java:305)
    at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:67)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:103)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:124)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:115)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    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:33)
    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)
我还尝试了这两个spring版本,但在这些解决方案中出现同样的错误对我没有帮助,因为我的pom.xml只有4.x版本


Eclipse Kepler版本am正在使用

根据Eclipse的配置方式,运行/调试配置可能在类路径上没有Spring库—在POM中没有Spring库是不够的

检查调试配置>{Your Debug Configuration}>Classpath
您可能需要首先手动将它们添加到“用户条目”下,以查看这是否是问题所在

根据Eclipse的配置方式,您的运行/调试配置可能在类路径上没有Spring库—在POM中没有Spring库是不够的

检查调试配置>{Your Debug Configuration}>Classpath
您可能需要首先在“用户条目”下手动添加它们,以查看这是否是问题所在

从表面上看,这似乎是jar版本的问题

我建议解决此版本问题的方法是使用

这将允许您跳过显式添加版本,并使最新版本可用

要使用BOM表,请将以下内容添加到您的部分:

<dependencyManagement> 
   <dependencies> 
    <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-framework-bom</artifactId> 
      <version>4.0.0.RC2</version> 
      <type>pom</type> 
      <scope>import</scope>
    </dependency> 
   </dependencies> 
</dependencyManagement>
 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
    </dependency>

org.springframework
spring框架bom表
4.0.0.RC2
聚甲醛
进口
然后,您可以简单地声明通常的Spring框架依赖项,而无需指定:

<dependencyManagement> 
   <dependencies> 
    <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-framework-bom</artifactId> 
      <version>4.0.0.RC2</version> 
      <type>pom</type> 
      <scope>import</scope>
    </dependency> 
   </dependencies> 
</dependencyManagement>
 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
    </dependency>

org.springframework
spring上下文
org.springframework
弹簧试验
测试

试一试,希望这能解决你的问题。

表面上看,这似乎是jar版本的问题

我建议解决此版本问题的方法是使用

这将允许您跳过显式添加版本,并使最新版本可用

要使用BOM表,请将以下内容添加到您的部分:

<dependencyManagement> 
   <dependencies> 
    <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-framework-bom</artifactId> 
      <version>4.0.0.RC2</version> 
      <type>pom</type> 
      <scope>import</scope>
    </dependency> 
   </dependencies> 
</dependencyManagement>
 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
    </dependency>

org.springframework
spring框架bom表
4.0.0.RC2
聚甲醛
进口
然后,您可以简单地声明通常的Spring框架依赖项,而无需指定:

<dependencyManagement> 
   <dependencies> 
    <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-framework-bom</artifactId> 
      <version>4.0.0.RC2</version> 
      <type>pom</type> 
      <scope>import</scope>
    </dependency> 
   </dependencies> 
</dependencyManagement>
 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
    </dependency>

org.springframework
spring上下文
org.springframework
弹簧试验
测试

试一试,希望这能解决您的问题。

基于Spring文档: ()必须将JUnit的版本设置为4.9和4.11之间

在Spring文档中检查JUnit版本很重要。这个可能会改变

以下是对Spring 4.1.7的解释:

SpringTestContext框架通过一个定制的运行程序(在JUnit4.9上测试)提供了与JUnit4.9+的完全集成 — 4.11). 通过使用@RunWith(SpringJUnit4ClassRunner.class)注释测试类,开发人员可以实现标准的基于JUnit的单元和集成测试,同时获得TestContext框架的好处,如支持加载应用程序上下文、测试实例的依赖注入、事务性测试方法执行、,等等


希望有此帮助。

基于Spring文档: ()必须将JUnit的版本设置为4.9和4.11之间

在Spring文档中检查JUnit版本很重要。这个可能会改变

以下是对Spring 4.1.7的解释:

SpringTestContext框架通过一个定制的运行程序(在JUnit4.9上测试)提供了与JUnit4.9+的完全集成 — 4.11). 通过使用@RunWith(SpringJUnit4ClassRunner.class)注释测试类,开发人员可以实现标准的基于JUnit的单元和集成测试,同时获得TestContext框架的好处,如支持加载应用程序上下文、测试实例的依赖注入、事务性测试方法执行、,等等


希望有帮助。

请提供一个最小的示例,该示例将通过执行路径尝试使用缺少的方法。我不能在本地复制这个。确保您运行的是您认为正在运行的。@SotiriosDelimanolis我已更新了我的问题。tnxTry在构建项目时运行测试,如果是maven项目,请不要跳过tests@VedantKekan是的,在eclipe上右键单击project->Run As->Maven Test对我很有效。谢谢:)@VedantKekan仍然在探索一种单独运行测试的方法,得到了我在问题中提到的相同的异常:(请提供一个最小的示例,该示例将通过执行路径尝试使用缺少的方法。我无法在本地复制此示例。请确保您运行的是您认为正在运行的内容。@SotiriosDelimanolis我已更新了我的问题。tnxTry在构建项目时运行测试,如果它是maven项目,请不要跳过tests@VedantKekan是的,在eclipe上右键单击project->Run As->Maven Test对我很有效。谢谢:)@VedantKekan仍然在探索一种单独运行测试的方法,得到了我在问题中提到的相同异常:(在类路径中,Maven Dependecies在用户条目下可用。在类路径中,Maven Dependecies在用户条目下可用。