Results 1 to 3 of 3

Thread: Run into NoSuchMethodError when load ApplicatioonContext in unit test.

  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Default Run into NoSuchMethodError when load ApplicatioonContext in unit test.

    Can some one kindly offer some help?

    Run into NoSuchMethodError when load ApplicatioonContext in unit test.
    Use springframework.integration-1.0.0 and spring-framework-2.5.6.
    I do have org.springframework.integration.stream-1.0.0.RELEASE.jar in classpath

    The exception trace:

    org.springframework.beans.factory.parsing.BeanDefi nitionParsingException: Configuration problem: Failed to import bean definitions from URL location[classpath*:/applicationContext.xml] Offending resource: file[C:\...\applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from URL [file:/applicationContext.xml]; nested exception is java.lang.NoSuchMethodError: org/springframework/beans/factory/support/BeanDefinitionBuilder.genericBeanDefinition(Ljava/lang/ClassLorg/springframework/beans/factory/support/
    BeanDefinitionBuilder;


    It is a very simple test

    public class TrialSpringIntegrationTest extends AbstractSingleSpringContextTests
    {
    private TrialService trialService;

    public void setTrialService(TrialService trialService)
    {
    this.trialService = trialService;
    }

    protected String[] getConfigLocations()
    {
    return "file:/applicationContext.xml",
    }

    public void testTimeRequest() throws Exception
    {
    Object obj = this.trialService.getTrialResult();

    assertNotNull(obj);
    }
    }

    ApplicationContext xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns=".../schema/integration"
    xmlns:xsi=".../XMLSchema-instance"
    xmlns:beans=".../schema/beans"
    xmlns:stream=".../integration/stream"
    xsi:schemaLocation=".../beans
    .../spring-beans-2.5.xsd
    .../integration
    .../integration/springintegration-1.0.xsd
    .../integration/stream
    .../stream/spring-integration-stream-1.0.xsd">

    <channel id="out_trial" />

    <channel id="in_trial" />
    <queue capacity="10"/>
    </channel>
    <service-activator input-channel="in_trial" ref="trialService" method="getTrialResult" output-channel="out_trial"/>

    <beans:bean id="trialService" class="com.xxx.xxx.TrialService"/>

    </beans:beans>

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    Can you check your classpath to verify that you have only one version of spring JARs?

  3. #3
    Join Date
    Jan 2009
    Posts
    2

    Default

    Verified that only one version of spring.jar is in classpath. Also search result of my hard drive also reveals that only one spring.jar exists.

    Then resort to:

    static
    {
    Class clazz = org.springframework.beans.factory.support.BeanDefi nitionBuilder.class;

    String className = clazz.getName();
    String resource = "/" + className.replace('.', '/') + ".class";
    System.out.println("Class " + className + " loaded from URL : " + clazz.getResource(resource));
    }

    to find out the BeanDefinitionBuilder is loaded from a legacy in-house built jar which was built on old version of spring.jar.

    What a day!

    Thanks a lot for the hint that leads to imply typical class loading issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •