les tests applicationContext: org.springframework.de base.annotation.AnnotationUtils.getAnnotationAttributes

J'ai donc cette classe d'assistance pour obtenir le contexte de l'application:

public class ApplicationContextProvider implements ApplicationContextAware{
    private static ApplicationContext context;
    public static ApplicationContext getApplicationContext() {
        return context;
    }
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        this.context = context;
    }
}

et son unité de test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class ApplicationContextProviderTest {

    @Test
    public void getApplicationContextInstance(){
        assertNotNull(ApplicationContextProvider.getApplicationContext());
    }
}

avec les ressources suivantes fichier (même paquetage de la classe de test):
ApplicationContextProviderTest-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util.xsd">

    <util:map id="contextProperties" />

    <bean id="applicationContextProvider"
          class="com.ideyatech.morphlynx.application.ApplicationContextProvider" />
</beans>

Quand je lance le test, j'obtiens cette erreur:

java.lang.IllegalStateException: Failed to introspect annotations: class com.ideyatech.morphlynx.application.listener.ApplicationContextProviderTest
at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:169)
at org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(AnnotatedElementUtils.java:93)
at org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(AnnotatedElementUtils.java:87)
at org.springframework.test.context.MetaAnnotationUtils$AnnotationDescriptor.<init>(MetaAnnotationUtils.java:305)
at org.springframework.test.context.MetaAnnotationUtils$UntypedAnnotationDescriptor.<init>(MetaAnnotationUtils.java:367)
at org.springframework.test.context.MetaAnnotationUtils$UntypedAnnotationDescriptor.<init>(MetaAnnotationUtils.java:362)
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptorForTypes(MetaAnnotationUtils.java:207)
at org.springframework.test.context.MetaAnnotationUtils.findAnnotationDescriptorForTypes(MetaAnnotationUtils.java:180)
at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:622)
at org.springframework.test.context.DefaultTestContext.<init>(DefaultTestContext.java:93)
at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:122)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:118)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:107)
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:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(Ljava/lang/annotation/Annotation;ZZ)Lorg/springframework/core/annotation/AnnotationAttributes;
at org.springframework.core.annotation.AnnotatedElementUtils$4.process(AnnotatedElementUtils.java:96)
at org.springframework.core.annotation.AnnotatedElementUtils$4.process(AnnotatedElementUtils.java:93)
at org.springframework.core.annotation.AnnotatedElementUtils.doProcess(AnnotatedElementUtils.java:198)
at org.springframework.core.annotation.AnnotatedElementUtils.process(AnnotatedElementUtils.java:165)
... 30 more
  • Comment puis-je résoudre ce problème? Je suppose que cela est causé par la mauvaise gestion des versions de spring core
  • Une meilleure façon de tester ApplicationContextProvider?

Merci!

  • Je suppose que cela est causé par la mauvaise gestion des versions de spring core Oui. Nous montrer les versions que vous utilisez.
  • Le projet utilise core-3.0.5.LIBÉRATION, mais ensuite j'ai été faire une erreur "Causé par: java.lang.ClassNotFoundException: org.springframework.de base.annotation.AnnotatedElementUtils". J'ai ajouté de base-4.0.5.LIBÉRATION pour le chemin de la classe, qui a été quand j'ai obtenu l'erreur dans mon post.
  • Quel est le Printemps d'autres libs?
  • la plupart sont également 3.0.5.De presse ou les 3.X.X.LIBÉRATION
  • Ne pas mélanger. Tous à être le même.
  • Donc je ne vais pas utiliser de cœur4.0.5.À la LIBÉRATION? Comment dois-je tester alors?

InformationsquelleAutor renz | 2014-08-08