Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Spring-data and MongoDB integration : noSuchbeandefinitionexception : No bean name "mongoTemplate"

 
Greenhorn
Posts: 8
Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring-data and MongoDB integration : noSuchbeandefinitionexception : No bean name "mongoTemplate" is defined.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mongoTemplate' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1102)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117)
at com.discusit.main.MainApp.main(MainApp.java:25)

XML(Application-context) is :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- <mongo:mongo host="127.0.0.1" port="27017" /> -->
<bean id="mongo" class="com.mongodb.Mongo" >
<constructor-arg name="host" value="127.0.0.1" />
<constructor-arg name="port" value="27017" />
</bean>
<!-- Following line not needed when you create instance of MongoOpearations
and MongoTemplate inside the main method <mongo:db-factory dbname="firstMongoDB"
/> -->
<context:component-scan base-package="com.discusit"></context:component-scan>
<!-- TRYING WITH MongoTemplate -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongo" />
<constructor-arg name="databaseName" value="test" />
</bean>
</beans>

Don't know what is wrong.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you also need a Mongo driver bean???

I am also wondering what

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

is about. Are you missing a jar.

Also, I believe the stacktrace you posted is not the entire stack trace.

Scroll to the bottom of the stack trace and work your way up till you hit your first "Caused by" from the bottom. That would be the root real cause.

But here is an example from a sample project I created a little bit ago



We also externalized some property values into a .properties file

Thanks

Mark
 
Aayushya Devmurari
Greenhorn
Posts: 8
Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark Spritzler, First of all thank you very much for replying,
Sir the stack trace that I Posted here is all I get, I ran the application again and checked that.
This is from an example which I got online here : http://www.mkyong.com/mongodb/spring-data-mongodb-hello-world-example/
I am not getting why others can run it and I can not.
 
Mark Spritzler
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because your configuration doesn't match what is in that blog.

As the example I posted and in the blog there is

<mongo:db-factory

Which is no where in your configuration.

Mark>
 
What's that smell? I think this tiny ad may have stepped in something.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic