Announcement Announcement Module
Collapse
No announcement yet.
spring data mongodb : issue with mongotemplate bean instantiation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring data mongodb : issue with mongotemplate bean instantiation

    Hi,
    i am using the following artifacts.
    spring-data-commons-core-1.2.1RELEASE.jar
    spring-data-mongodb-1.0.1.RELEASE.jar
    mongo-java-driver-2.7.3.jar

    Trying to build a simple REST based web app using spring data and mongodb.

    My spring web config file contains..
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:ws="http://www.springframework.org/schema/web-services"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd
    http://www.springframework.org/schema/web-services http://www.springframework.org/schem...rvices-1.5.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
    http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">


    <mongo:mongo id="mongo" host="localhost" port="27017"/>

    <mongo:db-factory id="mongoDbFactory" mongo-ref="mongo" dbname="dolphindb"/>

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.Mongo Template">
    <constructor-arg ref="mongoDbFactory" />
    </bean>

    </beans>


    Issue1 : I have a warning stating 'Unable to locate spring Namespace handler for the element mongo:db-factory of schema namespace 'http://www.springframework.org/schema/data/mongo'

    Issue2 : On starting the server i get the following exception stating that mongoTemplate instantiation failed.

    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mongoTemplate' defined in ServletContext resource [/WEB-INF/config/application-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplat e]: Constructor threw exception; nested exception is java.lang.IllegalAccessError: tried to access method org.springframework.core.GenericTypeResolver.getTy peVariableMap(Ljava/lang/ClassLjava/util/Map; from class org.springframework.data.util.ClassTypeInformation
    at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:288)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.autowireConstructor(Abs tractAutowireCapableBeanFactory.java:1003)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:907)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 91)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:222)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:288 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:425)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListe ner.contextInitialized(ContextLoaderListener.java: 47)
    at org.apache.catalina.core.StandardContext.listenerS tart(StandardContext.java:3934)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4429)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:516)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:413)
    Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplat e]: Constructor threw exception; nested exception is java.lang.IllegalAccessError: tried to access method org.springframework.core.GenericTypeResolver.getTy peVariableMap(Ljava/lang/ClassLjava/util/Map; from class org.springframework.data.util.ClassTypeInformation
    at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:141)
    at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:108)
    at org.springframework.beans.factory.support.Construc torResolver.autowireConstructor(ConstructorResolve r.java:280)
    ... 29 more
    Caused by: java.lang.IllegalAccessError: tried to access method org.springframework.core.GenericTypeResolver.getTy peVariableMap(Ljava/lang/ClassLjava/util/Map; from class org.springframework.data.util.ClassTypeInformation
    at org.springframework.data.util.ClassTypeInformation .<init>(ClassTypeInformation.java:96)
    at org.springframework.data.util.ClassTypeInformation .<clinit>(ClassTypeInformation.java:42)
    at org.springframework.data.mongodb.core.convert.Defa ultMongoTypeMapper.<clinit>(DefaultMongoTypeMapper .java:45)
    at org.springframework.data.mongodb.core.convert.Mapp ingMongoConverter.<init>(MappingMongoConverter.jav a:103)
    at org.springframework.data.mongodb.core.MongoTemplat e.getDefaultMongoConverter(MongoTemplate.java:1543 )
    at org.springframework.data.mongodb.core.MongoTemplat e.<init>(MongoTemplate.java:198)
    at org.springframework.data.mongodb.core.MongoTemplat e.<init>(MongoTemplate.java:184)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:513)
    at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:126)
    ... 31 more

    Would appreciate any help ..

    Thanks in advance...
    Last edited by manish86b; Mar 9th, 2012, 10:03 AM.

  • #2
    I was able to fix this problem by just upgrading my spring framework core jars from 3.0.5 to 3.1.1.
    Thanks.

    Comment

    Working...
    X