takimafr / spring-dbunit

DBUnit support for Spring
Apache License 2.0
40 stars 19 forks source link

NoSuchMethodError: GenericApplicationContext.getEnvironment() ConfigurableEnvironment #17

Closed ytsejammer closed 11 years ago

ytsejammer commented 11 years ago

Hello,

I started using version spring-dbunit-test:1.1.9 and I ran into the following problem:


java.lang.NoSuchMethodError: org.springframework.context.support.GenericApplicationContext.getEnvironment()Lorg/springframework/core/env/ConfigurableEnvironment;
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:97)
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
    at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)

I am using Spring 3.1.2.RELEASE and also Spring Security. I found out that excluding some of the dependencies of spring-security-code fixes the problem.


<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>${springframework.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>

I found a quick fix thanks to Matt Raible's following blog post: http://raibledesigns.com/rd/entry/upgrading_appfuse_to_spring_security

I hope this can be documented somewhere and save a couple of minutes to the next person starting with this great utility.

slandelle commented 11 years ago

As I understand it, it seems that you mix modules from Spring 3.0.X and modules from Spring 3.1.X. This is simply a bad maven usage.

Instead of playing with exclusions , you'd better use a dependencyManagement block in order to ensure that all your modules match.