Проблемы запуска Spring с JUnit

1

У меня есть следующее, когда вы пытаетесь запустить простой тест (пока нет никаких реальных утверждений) с использованием Eclipse, Spring и JUnit. Вот о чем он жалуется:

java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;

Я нашел аналогичную проблему в StackOverflow здесь: Spring JUnit Test Error

Итак, я предположил, что проблема связана с несоответствием пружинных зависимостей. Однако, похоже, это не работает для меня. В принципе, если я правильно понимаю, что эта ссылка говорит о решении, заключается в том, чтобы явно объявить версию моих зависимостей от Spring в файле pom, который я делаю (я объявляю, что все зависимости имеют версии 3.1.x).

Когда я смотрю на ~/м2, я могу найти эти установки до 3.1, даже когда я удалю их все и снова запустим сборку maven:

./spring-aop/3.0.4.RELEASE
./spring-aop/3.0.7.RELEASE
./spring-asm/3.0.4.RELEASE
./spring-asm/3.0.7.RELEASE
./spring-beans/3.0.4.RELEASE
./spring-beans/3.0.7.RELEASE
./spring-context/3.0.4.RELEASE
./spring-context/3.0.7.RELEASE
./spring-core/3.0.4.RELEASE
./spring-core/3.0.7.RELEASE
./spring-expression/3.0.4.RELEASE
./spring-expression/3.0.7.RELEASE
./spring-jdbc/3.0.7.RELEASE
./spring-parent/3.0.4.RELEASE
./spring-parent/3.0.7.RELEASE
./spring-tx/3.0.7.RELEASE
./spring-web/3.0.4.RELEASE
./spring-web/3.0.7.RELEASE

У меня нет ничего с этими номерами версий в моем файле pom, поэтому что-то явно называет их. Есть ли способ убедиться, что они не установлены? Или, если они должны быть там, потому что они зависят от других депов, как я могу убедиться, что мой тестовый контекст не использует те, кроме 3.1, вместо этого?

Это то, что я пытаюсь запустить:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sample.persistence.manager.ProfileManager;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={ JpaTestConfig.class, TestConfig.class })
public class ProfileManagerTest {

    @Autowired
    private ProfileManager profileManager;

    @Test
    public void testCreateAndRetrieve() {

    }

}

pom.xml:

      <project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.sample</groupId>
        <artifactId>common</artifactId>
        <version>0.1-SNAPSHOT</version>
        <packaging>jar</packaging>
        <name>common</name>

        <parent>
            <groupId>com.sample</groupId>
            <artifactId>ws-parent</artifactId>
            <version>0.1-SNAPSHOT</version>
            <relativePath>..</relativePath>
        </parent>

        <properties>
            <spring.security.version>3.1.3.RELEASE</spring.security.version>
            <spring.framework.version>3.1.1.RELEASE</spring.framework.version>        
            <hibernate.version>3.6.0.Final</hibernate.version>
            <commons-dbcp.version>1.2.2</commons-dbcp.version>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-asm</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>        

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>        

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>                

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-parent</artifactId>
                <version>3.1.1.RELEASE</version>
                <type>pom</type>
            </dependency>        

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>        

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>        

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.ws</groupId>
                <artifactId>spring-oxm-tiger</artifactId>
                <version>1.5.4</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-core</artifactId>
                <version>${spring.security.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
                <version>${spring.security.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-config</artifactId>
                <version>${spring.security.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
                <version>${spring.framework.version}</version>
            </dependency>        

            <dependency>
                <groupId>com.relayrides</groupId>
                <artifactId>pushy</artifactId>
                <version>0.1.1</version>
            </dependency>

            <dependency>
                <groupId>org.versly</groupId>
                <artifactId>versly-wsdoc</artifactId>
                <version>1.0-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>

            <dependency>
                <groupId>com.amazonaws</groupId>
                <artifactId>aws-java-sdk</artifactId>
                <version>1.4.2.1</version>
            </dependency>

            <!-- Hibernate -->

            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>${hibernate.version}</version>
            </dependency>

            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-ehcache</artifactId>
                <version>${hibernate.version}</version>
            </dependency>

            <!--
                    <dependency>
                        <groupId>javax.persistence</groupId>
                        <artifactId>persistence-api</artifactId>
                        <version>${javax.persistence.version}</version>
                    </dependency>
            -->

            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>${commons-dbcp.version}</version>
            </dependency>

            <dependency>
                <groupId>cglib</groupId>
                <artifactId>cglib</artifactId>
                <version>2.2</version>
            </dependency>

            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.5</version>
            </dependency>

            <dependency>
                <groupId>commons-beanutils</groupId>
                <artifactId>commons-beanutils</artifactId>
                <version>1.8.3</version>
            </dependency>

            <dependency>
                <groupId>javax.annotation</groupId>
                <artifactId>jsr250-api</artifactId>
                <version>1.0</version>
            </dependency>

            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
                <version>1.8.4</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.4</version>
            </dependency>

            <dependency>
                <groupId>com.googlecode.json-simple</groupId>
                <artifactId>json-simple</artifactId>
                <version>1.1.1</version>
            </dependency>


            <dependency>
                <groupId>hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
                <version>1.8.0.10</version>
            </dependency>
        </dependencies>

        <build>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
                <resource>
                    <directory>src/main/sertificates</directory>
                </resource>
            </resources>
            <filters>
                <filter>../${build.profile}.properties</filter>
            </filters>

            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.5.7.201204190339</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                </plugin>

                <plugin>
                    <groupId>org.bsc.maven</groupId>
                    <artifactId>maven-processor-plugin</artifactId>
                    <version>1.3.6</version>

                    <configuration>
                        <outputDiagnostics>true</outputDiagnostics>
                        <processors>
                            <processor>org.versly.rest.wsdoc.AnnotationProcessor</processor>
                        </processors>
                    </configuration>

                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>process</goal>
                            </goals>
                        </execution>
                    </executions>

                    <dependencies>

                        <dependency>
                            <groupId>org.versly</groupId>
                            <artifactId>versly-wsdoc</artifactId>
                            <version>1.0-SNAPSHOT</version>
                            <scope>compile</scope>
                        </dependency>
                    </dependencies>
                </plugin>

                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.2</version>

                    <executions>
                        <execution>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>java</goal>
                            </goals>

                            <configuration>
                                <mainClass>org.versly.rest.wsdoc.RestDocAssembler</mainClass>
                                <arguments>
                                    <argument>${project.build.directory}/classes</argument>
                                </arguments>
                            </configuration>

                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
            </plugins>
            <pluginManagement>
                   <plugins>
                           <!--This plugin configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                           <plugin>
                                   <groupId>org.eclipse.m2e</groupId>
                                   <artifactId>lifecycle-mapping</artifactId>
                                   <version>1.0.0</version>
                                   <configuration>
                                           <lifecycleMappingMetadata>
                                                   <pluginExecutions>
                                                           <pluginExecution>
                                                                   <pluginExecutionFilter>
                                                                           <groupId>org.jacoco</groupId>
                                                                           <artifactId>
                                                                                   jacoco-maven-plugin
                                                                           </artifactId>
                                                                           <versionRange>
                                                                                   [0.5.7.201204190339,)
                                                                           </versionRange>
                                                                           <goals>
                                                                                   <goal>prepare-agent</goal>
                                                                           </goals>
                                                                   </pluginExecutionFilter>
                                                                   <action>
                                                                           <ignore></ignore>
                                                                   </action>
                                                           </pluginExecution>
                                                   </pluginExecutions>
                                           </lifecycleMappingMetadata>
                                   </configuration>
                           </plugin>
                   </plugins>
            </pluginManagement>        
        </build>
    </project>
Теги:
maven
spring
spring-mvc
junit

1 ответ

2
Лучший ответ

Попробуйте исключить весна-ооп, весенние бобы, весенний контекст, весеннюю яму, весеннее выражение, spring-jdbc и spring-tx из зависимостей весенней безопасности.

Spring Security 3.1.3 имеет зависимости от всех вышеупомянутых весенних банок для версии 3.0.7.RELEASE

Подробнее о том, как добавить исключения здесь: Как обрабатывать зависимости подпроектов в Maven

  • 0
    Этот прибил это! Спасибо!

Ещё вопросы

Сообщество Overcoder
Наверх
Меню