Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4077422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:32:53+00:00 2026-05-20T17:32:53+00:00

The Google Code site of Morphia says it works great with Guice, Spring, and

  • 0

The Google Code site of Morphia says it “works great with Guice, Spring, and other DI frameworks.”

I’m learning Spring at the moment, so i’m just experimenting with connecting these two tools.
I’ve created a User POJO to store user objects with Morphia in MongoDB. I’ve also created a UserDAO class extending BasicDAO from Morphia to access objects.

My Spring application context configuration XML looks like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
           xmlns:aop="http://www.springframework.org/schema/aop">

      <bean class="java.lang.String" id="mongoDb">
        <constructor-arg value="test"/>
      </bean>

      <bean class="com.google.code.morphia.Morphia" id="morphia" />
      <bean class="com.mongodb.Mongo" id="mongo"/>
      <bean class="hu.inagy.testspring.daos.UserDAO" id="userDao">
        <constructor-arg ref="morphia" index="0" />
        <constructor-arg ref="mongo" index="1" />
        <constructor-arg ref="mongoDb" index="2" />
      </bean>

    </beans>

I have a simple main class to test functionality:

  public class App 
  {
      public static void main( String[] args )
      {
          ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/app-context.xml");
          UserDAO userDao = (UserDAO) applicationContext.getBean("userDao");

          userDao.deleteByQuery(userDao.createQuery());

          User user = new User();
          user.setName("Test");
          userDao.save(user);

          User ret = userDao.find().get();
          System.out.println("Saved user is: "+ret);
      }
  }

This works fine, however i don’t know if i did everything as it should be. For example i haven’t called ensureIndexes() and ensureCaps() on the datastore. My code also doesn’t have an explicit mapping call for the POJOs on the Morphia object.

Are these done for me automatically or should i do other things to use Morphia correctly with Spring?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:32:54+00:00Added an answer on May 20, 2026 at 5:32 pm

    I don’t use spring but this articles seems to talk about exactly what you need, a hook to do things when you app starts: http://leshazlewood.com/2007/07/30/spring-application-bootstrap-data/

    You can do the Datastore.ensureIndexes/Caps() there.

    You can also read this thread about using @Autowire and annotations instead of the xml, if you like that stuff.

    http://groups.google.com/group/morphia/browse_thread/thread/1013b17963f29468

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked all over the Google code site but am just not finding anything
I am learning the Javascript tips from this http://code.google.com/p/jslibs/wiki/JavascriptTips site. I came to see
I'm trying to integrate google-code-prettify to my site in order to prettify Java code.
My site using heavy javascripts. So can i upload them in google code and
I'm following the barcode tutorial for this site: http://brismith66.blogspot.com/2010_07_01_archive.html using the google code: http://code.google.com/p/wsdl2objc/
I am developing a site to add events to a Google Calendar using code
I have installed the below google tracking code in my site var _gaq =
I have implemented admob code as given in google site (http://code.google.com/mobile/ads/docs/android/fundamentals.html) as described in
I added following standard Google Plus One code to my web site. <!-- Place
http://code.google.com/p/mvc-mini-profiler/ This looks amazing, and I'm really excited about it, but my site is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.