0

Currently I am using Spring-data-mongodb in my project and it works perfectly for me.

<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-mongodb</artifactId>
  <version>1.1.0.RELEASE</version>
</dependency>

I want to use aggregation framework in my project so I updated version to latest one i.e. 1.8.0

<groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>1.8.0.RELEASE</version>
</dependency>

After update maven dependency it gives error while runing application

Jan 11, 2016 10:48:07 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.spring.SpringContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlReaderContext.getEnvironment()Lorg/springframework/core/env/Environment;

But when I switch to version 1.1.0 it works perfectly without any error. I tried to clean all downloaded data from ~/.m2 folder and refresh again still same problem.Any idea what I am missing ?

<?xml version="1.0" encoding="UTF-8"?>
<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.pt</groupId>
    <artifactId>pt-pro</artifactId>
    <name>pt-pro</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>

    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <!-- Joda TIme dependency for date and time -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.3</version>
        </dependency>

        <!-- open css -->
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
        </dependency>
        <!-- voice call service -->
        <dependency>
            <groupId>com.twilio.sdk</groupId>
            <artifactId>twilio-java-sdk</artifactId>
            <version>3.4.5</version>
        </dependency>
        <!-- Apache http client -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.4.1</version>
        </dependency>


        <!-- Blur image -->
        <dependency>
            <groupId>nu.pattern</groupId>
            <artifactId>opencv</artifactId>
            <version>2.4.9-4</version>
        </dependency>

        <!-- ReCaptcha -->
        <dependency>
            <groupId>net.tanesha.recaptcha4j</groupId>
            <artifactId>recaptcha4j</artifactId>
            <version>0.0.7</version>
        </dependency>
        <!-- MongoDB -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>1.2.0.RELEASE</version>
        </dependency>

.......

Prashant Thorat
  • 1,752
  • 11
  • 33
  • 54
  • 1
    This looks like a dependency issue, what is the version of Spring-beans jar ? – M4ver1k Jan 11 '16 at 05:42
  • 1
    We need to see all dependencies used to help.. –  Jan 11 '16 at 05:43
  • I updated my quetion with pom.xml. After updating 3.1.1.RELEASE to 4.2.1.RELEASE it gives error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.path()[Ljava/lang/String; – Prashant Thorat Jan 11 '16 at 06:54

2 Answers2

0

It's for sure dependency conflict.

In the new version (1.8.0), there is no method getEnvironment(), as it is stated in the log.

Updating the dependencies version is quite a tricky process, you need to check which version of each dependency you need to use to avoid this kind of errors - something that works in 1.1.0, without conflicts can cause errors after update.

UPDATE Please check if adding, will help you:

  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.2.4.RELEASE</version>
  </dependency>

This configuration works fine for Mongo 1.2.0

<!-- Spring framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.2.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.2.2.RELEASE</version>
        </dependency>

        <!-- mongodb java driver -->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>2.11.0</version>
        </dependency>

        <!-- Spring data mongodb -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
            <version>1.2.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
m.aibin
  • 3,528
  • 4
  • 28
  • 47
  • Yes its dependency conflict but how to solve it? I need aggregation framework that is updated in 1.1.6 and above versions – Prashant Thorat Jan 11 '16 at 05:45
  • I tried your configuration it runs my application but Aggregation cases and methods not found. My code is Aggregation agg = newAggregation( match(Criteria.where("id").is( "pt123")), group("parentId", "categoryId", "llcId").count().as("total"), project("total").and("parentId").previousOperation(), sort(Sort.Direction.DESC, "total")); can not import clases – Prashant Thorat Jan 11 '16 at 06:25
  • Hmm, I found this: Spring Data MongoDB provides support for the Aggregation Framework introduced to MongoDB in version 2.2. – m.aibin Jan 11 '16 at 06:29
  • Look also here: http://examples.javacodegeeks.com/enterprise-java/spring/spring-data-mongodb-example/ – m.aibin Jan 11 '16 at 06:32
  • could not switch from 3.2.1 org.springframework-version to 4.2.1 .another issue like org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapp‌​ing': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.path()[Ljava/lang/String; updated my quetion with pom.xml – Prashant Thorat Jan 11 '16 at 07:03
0

It looks like dependency problem in spring-core, spring-data-mongodb version 1.1.0 uses 3.1.2.RELEASE version of spring-core, and version 1.8.0 uses 4.2.4.RELEASE, make sure that this jars packaged.

aios
  • 231
  • 2
  • 10