1

I an having the following when trying to run a simple test (no real assertions yet) using Eclipse, Spring and JUnit. Here is what it complains about:

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

I have found a similar issue on StackOverflow here: Spring JUnit Test Error

So, I supposed the problem was due to spring dependencies mismatch. However, it doesn't seem to work for me. Basically, if I understand it right what that link says the solution is, is to declare explicitly the version of my spring dependencies on the pom file, which I am doing (I am declaring all dependencies to have 3.1.x versions).

When I look at ~/m2, I can find these prior-to-3.1 dependencies installed, even when I remove them all and run maven build again:

./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

I don't have anything with these version numbers on my pom file so something is clearly calling them. Is there a way to make sure these are not installed? Or, if they need to be there because they are dependencies from other deps, how can I make sure my test context doesnt use those but 3.1 instead?

This is what I am trying to run:

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's 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>
Community
  • 1
  • 1
marcelorocks
  • 2,005
  • 3
  • 18
  • 28
  • can you post your `pom.xml` ? – Santosh Joshi Mar 12 '14 at 18:11
  • ok, just added to the main question – marcelorocks Mar 12 '14 at 18:17
  • By the way, I can see on eclipse, the dependencies hierarchy, and I can see some dependencies trying to get the transitive 3.0.x version for other libraries. I just dont know how to force it not to get those but get 3.1. instead – marcelorocks Mar 12 '14 at 18:19
  • if you can find out `3.0.x` version jar in eclipse then right click on those and selected `exclude maven artifact' – Santosh Joshi Mar 12 '14 at 18:31
  • 1
    you are getting these dependencies because of spring-security jars. – Santosh Joshi Mar 12 '14 at 18:45
  • Yes, and that is probably what is kicking the error. I think the question remains, how to fix it... – marcelorocks Mar 12 '14 at 18:56
  • i already posted above, if using eclipse then open `pom.xml` and got to `dependencies hierarchy` view search for `spring 3.0.x` dependancies, Right click on them the then select `Exclude Maven Artifact` – Santosh Joshi Mar 12 '14 at 19:01
  • sorry, I should have replied to that. That doesn't fix it. It removes the entire dependency from pom, not the version specific one. – marcelorocks Mar 12 '14 at 19:05
  • I added the same pom to my project, it is showing the 3.0.x jar but with ommited state. are you using Spring MVC ? – Santosh Joshi Mar 12 '14 at 19:10
  • Yes, using Spring MVC. In my eclipse it shows omitted state too. But it still gets downloaded by maven into ~/.m2, and I still get the errors – marcelorocks Mar 12 '14 at 19:24
  • you need to check your projects /`WEB-INF/lib` folder. `Maven` might have downloaded these jar ealier. and I believe the jars at `~/.m2`should not create problems for your project – Santosh Joshi Mar 12 '14 at 19:35
  • Just clean the temp and work directory of your `tomcat` and things should run fine – Santosh Joshi Mar 12 '14 at 19:36
  • @SantoshJoshi, I am trying to run a test. There is no tomcat. – marcelorocks Mar 12 '14 at 20:12
  • 1
    Why can't you add an exclusion to the dependencies for Spring Security (or whatever dependency is pulling in the bad JAR versions)? Something like the answer here: http://stackoverflow.com/questions/3659810/how-to-handle-sub-projects-dependencies-in-maven – CodeChimp Mar 12 '14 at 20:27

1 Answers1

2

Try excluding spring-aop, spring-beans, spring-context, spring-core, spring-expression, spring-jdbc and spring-tx from the spring security dependencies.

Spring Security 3.1.3 has dependencies to all the aforementioned spring jars for version 3.0.7.RELEASE

More details on how to add exclusions here: How to handle sub projects dependencies in Maven

Community
  • 1
  • 1
geoand
  • 60,071
  • 24
  • 172
  • 190