Prüfung der Datei ApplicationContext: org.springframework.core.Anmerkung.AnnotationUtils.getAnnotationAttributes
So habe ich diese helper-Klasse für die Anwendung Kontext:
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;
}
}
und seine unit-test:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class ApplicationContextProviderTest {
@Test
public void getApplicationContextInstance(){
assertNotNull(ApplicationContextProvider.getApplicationContext());
}
}
mit der folgenden Ressource-Datei (gleiche Paket mit test-Klasse):
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>
Wenn ich den test, bekomme ich diesen Fehler:
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
- Wie kann ich dieses Problem beheben? Ich vermute, dass dies wird verursacht durch falsche Versionierung von Federkern -
- Keine bessere Möglichkeit zu testen, ApplicationContextProvider?
Dank!
ich vermute, dass dies wird verursacht durch falsche Versionierung von spring-core ja. Zeigen Sie uns die Versionen, die Sie verwenden.
Das Projekt nutzt core-3.0.5.RELEASE, aber dann war ich immer eine Fehlermeldung "Caused by: java.lang.ClassNotFoundException: org.springframework.core.Anmerkung.AnnotatedElementUtils". Ich fügte hinzu, core-4.0.5.RELEASE, um den classpath, das war, als ich den Fehler in meinem post.
Was ist mit den anderen Spring libs?
die meisten sind auch 3.0.5.RELEASE oder 3.X.X.RELEASE
Don ' T mix. Haben Sie alle die gleichen sein werden.
Das Projekt nutzt core-3.0.5.RELEASE, aber dann war ich immer eine Fehlermeldung "Caused by: java.lang.ClassNotFoundException: org.springframework.core.Anmerkung.AnnotatedElementUtils". Ich fügte hinzu, core-4.0.5.RELEASE, um den classpath, das war, als ich den Fehler in meinem post.
Was ist mit den anderen Spring libs?
die meisten sind auch 3.0.5.RELEASE oder 3.X.X.RELEASE
Don ' T mix. Haben Sie alle die gleichen sein werden.
InformationsquelleAutor renz | 2014-08-08
Du musst angemeldet sein, um einen Kommentar abzugeben.
Fand ich den gleichen Fehler beim testen von Spring Security 4.0.0.M1.
Mit 3.2.4.RELEASE gibt es keine Probleme.
Versuchen Sie es mit der 3.2.4.RELEASE.
InformationsquelleAutor 0xmilk_
Es stellte sich heraus, dass ich verwenden soll, spring-test-3.0.5, wie die version von meinem spring-jars.
InformationsquelleAutor renz
Habe ich diesen Fehler Meldung beim Umgang mit Apache Tomcat-webapps.
Ein Glas/Klasse könnte in der Umgebungsvariable classpath, wenn Apache Tomcat wird gestartet UND auch innerhalb des webapp-Klassen/lib-Ordner.
Die Lösung ist in diesem Fall entfernen Sie die doppelten class - /jar.
InformationsquelleAutor Jose Leon