Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Core Container

Reply
 
Thread Tools Display Modes
  #1  
Old Oct 23rd, 2007, 02:25 PM
Narada Narada is offline
Senior Member
 
Join Date: Jan 2007
Posts: 106
Default Spring 2.5-rc1 test context framework error

Hi,

I'm using Spring 2.5-rc1 test context framework.

When I do this:

Code:
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({})
public class TestContext {

    @Test
    public void testTrue() {
        assertTrue(true);
    }

}
or:

Code:
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:src/test/resources/context.xml" })
public class TestContext {

    @Test
    public void testTrue() {
        assertTrue(true);
    }

}
I get:

Code:
java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Class;
        at org.springframework.test.context.TestContext.retrieveContextLocations(TestContext.java:159)
        at org.springframework.test.context.TestContext.<init>(TestContext.java:115)
        at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:106)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:114)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:80)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
        at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:26)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:24)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:40)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:30)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
What I expect to happen is that spring loads the context file which looks as below.

Code:
<?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-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"
    default-lazy-init="true">

    <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" lazy-init="false" />

    <import resource="classpath:com/foo/bar/wc/dl/context/*.xml" />

    <util:properties id="bar.wc.HibernateProperties" location="classpath:bar.wc.hibernate.properties" />
</beans>
What am I doing wrong? I am using Junit4. I noticed that when I comment out:

Code:
@RunWith(SpringJUnit4ClassRunner.class)
then it runs fine but in the log output I see no spring context loading and the test passes. Ideally the context should load and then fail part way because the datasource bean is missing but as I said it does not even try to load the context.

Any help much appreciated.
Reply With Quote
  #2  
Old Oct 23rd, 2007, 02:56 PM
Marten Deinum Marten Deinum is online now
Senior Member
 
Join Date: Jun 2006
Location: The Netherlands
Posts: 9,523
Default

Try the JUnit shipped with Spring instead of the one shipped with Eclipse. Also make sure you don't have duplicate classes/jars on your classpath.
__________________
Marten Deinum
  • Senior Java Consultant
  • SpringSource Certified Trainer
Conspect ICT diensten
Blog
LinkedIn
Use the [ code ] tags, young padawan
Reply With Quote
  #3  
Old Oct 23rd, 2007, 07:47 PM
Sam Brannen Sam Brannen is offline
Senior Member
 
Join Date: Jan 2006
Location: Zürich, Switzerland
Posts: 400
Default

Hi Narada,

Quote:
Originally Posted by Narada View Post
I'm using Spring 2.5-rc1 test context framework.

Code:
java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.findAnnotationDeclaringClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Class;
What am I doing wrong?
The Spring TestContext Framework requires Spring 2.5 (or rather 2.5 RC1 at the moment). Based on the fact that a NoSuchMethodError was thrown for AnnotationUtils.findAnnotationDeclaringClass(...), it appears that you do not have the latest Spring JARs on your classpath for your test (or as Marten pointed out, that you have duplicate JARs or classes on the classpath), as the AnnotationUtils.findAnnotationDeclaringClass() method was introduced in 2.1 M4.

So basically, just make sure you are using spring.jar and spring-test.jar from 2.5 RC1, and that should do the trick.

Cheers,

Sam
Reply With Quote
  #4  
Old Oct 24th, 2007, 03:49 AM
Narada Narada is offline
Senior Member
 
Join Date: Jan 2007
Posts: 106
Default

Hi. Thanks all. This issue is now resolved. I was using maven and had Spring 2.0.7 stable as compile time dependency and Spring-Test 2.5-rc1 as test time dependency so that I could use the test context framework. However I switched to the latter for both now by altering version in pom file. Now it works fine. Thanks. (Now to decide whether to use 2.5-rc1 in production ;)
Reply With Quote
  #5  
Old Oct 25th, 2007, 05:06 AM
dyn dyn is offline
Junior Member
 
Join Date: Aug 2004
Location: Budapest, Hungary
Posts: 24
Default

Narada, you say you found a repository where Spring 2.5-rc1 is publicly avalaible? I'd love to know where to get it from with maven..
Reply With Quote
  #6  
Old Oct 25th, 2007, 05:21 AM
Sam Brannen Sam Brannen is offline
Senior Member
 
Join Date: Jan 2006
Location: Zürich, Switzerland
Posts: 400
Default

Quote:
Originally Posted by dyn View Post
Narada, you say you found a repository where Spring 2.5-rc1 is publicly avalaible? I'd love to know where to get it from with maven..
This topic was brought up for the 2.1 M4 release as well. See Ben Hale's response here:

http://forum.springframework.org/sho...79&postcount=3

Note: Ben mentions two different URLs. The one at s3browse.com is solely for browsing the repository within a web browser; whereas, the one at s3.amazonaws.com is the actual URL to use with Maven.

Regards,

Sam
Reply With Quote
  #7  
Old Oct 25th, 2007, 05:22 AM
Marten Deinum Marten Deinum is online now
Senior Member
 
Join Date: Jun 2006
Location: The Netherlands
Posts: 9,523
Default

This blog post explains where to get Spring Portfolio maven artifacts and how the releases are managed/published.
__________________
Marten Deinum
  • Senior Java Consultant
  • SpringSource Certified Trainer
Conspect ICT diensten
Blog
LinkedIn
Use the [ code ] tags, young padawan
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:34 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.