Could not load TestContextBootstrapper - Spring Unit testing

后端 未结 3 1662
终归单人心
终归单人心 2020-12-11 00:40

I have to execute Unit test on one of my Dao classes using Spring. Here is my unit test:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locati         


        
相关标签:
3条回答
  • 2020-12-11 01:12

    In my case it was a version conflict caused by activemq-all. That dependency (5.12.2 in my case) includes an incompatible version of spring (I just upgraded to spring 4.3.4). So, save yourself a few hours of debugging and check not only the Dependency Hierarchy in your favorite IDE, but also look inside those jar files to see if any are embedding org.springframework packages.

    0 讨论(0)
  • 2020-12-11 01:12

    Maarten is correct. Here is my new list of dependencies in pom.xml which worked for me:

    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.34</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.5.4-Final</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.4.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.3.0.ga</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    </dependencies>
    
    0 讨论(0)
  • 2020-12-11 01:23

    It is probably a version conflict since you are using a old version of base spring (2.5.6) with very new one (4.1.4.RELEASE) for your test en context includes

    0 讨论(0)
提交回复
热议问题