EzDevInfo.com

spring-data-mongodb

Provide support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access. Spring Data MongoDB

MongoDB-CR Authentication failed

I am getting following error while authenticating user : purchase_user@purchase failed. MongoDB-CR Authentication failed. Missing credentials in user document when I access webservice through browser.

But I am able to authenticate purchase_user from mongo it returns 1 .


Source: (StackOverflow)

What's the difference between Spring Data's MongoTemplate and MongoRepository?

I need to write an application with which I can do complex queries using spring-data and mongodb. I have been starting by using the MongoRepository but struggled with complex queries to find examples or to actually understand the Syntax.

I'm talking about queries like this:

@Repository
public interface UserRepositoryInterface extends MongoRepository<User, String> {
    List<User> findByEmailOrLastName(String email, String lastName);
}

or the use of JSON based queries which I tried by trial and error because I don't get the syntax right. Even after reading the mongodb documentation (non-working example due to wrong syntax).

@Repository
public interface UserRepositoryInterface extends MongoRepository<User, String> {
    @Query("'$or':[{'firstName':{'$regex':?0,'$options':'i'}},{'lastName':{'$regex':?0,'$options':'i'}}]")
    List<User> findByEmailOrFirstnameOrLastnameLike(String searchText);
} 

After reading through all the documentation it seems that mongoTemplate is far better documented then MongoRepository. I'm referring to following documentation:

http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/reference.html

Can you tell me what is more convenient and powerful to use? mongoTemplate or MongoRepository? Are both same mature or does one of them lack more features then the other?


Source: (StackOverflow)

Advertisements

Store Java 8 Instant as BSON date using SpringData-MongoDB

I have the following class that I want to store in MongoDB using Spring Data

@Document()
public class Tuple2<T extends Enum<T>> {

@Id
private String id;

@Indexed
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private final Instant timeCreated;

...
}

DateTimeFormat annotation javadoc states:

Declares that a field should be formatted as a date time. Supports formatting by style pattern, ISO date time pattern, or custom format pattern string. Can be applied to java.util.Date, java.util.Calendar, java.long.Long, Joda-Time value types; and as of Spring 4 and JDK 8, to JSR-310 java.time types too.

I am using Spring 4.1.1 and JDK 8, so I'd expect that it applies to Instant. However, here's what is actually stored:

"timeCreated" : {
    "seconds" : NumberLong(1416757496),
    "nanos" : 503000000
}

If I write and register custom convertor from Instant to Date like explained in this answer then it works, however I'd like to avoid that, as I am sure there must be a better way.

After further digging in Spring source code I've found the following class Jsr310DateTimeFormatAnnotationFormatterFactory which looks promising:

Formats fields annotated with the DateTimeFormat annotation using the JSR-310 java.time package in JDK 8.

Its' source does not reference Instant, but it does reference OffsetTime and LocalTime. Even so, when I change Instant to be OffsetDateTime in my example, it is still stored as a composite object instead of ISODate.

What is missing?


Source: (StackOverflow)

How to return raw JSON directly from a mongodb query in Java?

I have the following code:

@RequestMapping(value = "/envinfo", method = RequestMethod.GET)
@ResponseBody
public Map getEnvInfo()
{
    BasicQuery basicQuery = new BasicQuery("{_id:'51a29f6413dc992c24e0283e'}", "{'envinfo':1, '_id': false }");
    Map envinfo= mongoTemplate.findOne(basicQuery, Map.class, "jvmInfo");
    return envinfo;
}

As you can notice, the code:

  1. Retrieves JSON from MongoDB
  2. Converts it to a Map object
  3. The Map object is then converted to JSON by Spring MongoData before it is returned to the browser.

Is it possible to directly return the raw json from MongoDb without going through the intermediate conversion steps?


Source: (StackOverflow)

Spring -Data MongoDB issue with field which is an interface

I'm using Spring-Data for MongoDB:

Version information - org.mongodb.mongo-java-driver version 2.10.1, org.springframework.data.spring-data-mongodb version 1.2.1.RELEASE.

I have a case that's similar to the one defined in here, which is (sorry for the formatting...):

I just started developing some app in Java with spring-data-mongodb and came across some issue that I haven't been able to solve:

I have a couple of document beans like this:

@Document(collection="myBeanBar")
public class BarImpl implements Bar {
    String id;
    Foo foo;
    // More fields and methods ... 
}

@Document
public class FooImpl implements Foo {
    String id;
    String someField;
    // some more fields and methods ...
} 

And I have a repository class with a method that simply invokes a find similar to this:

public List<? extends Bar> findByFooField(final String fieldValue) {
    Query query = Query.query(Criteria.where("foo.someField").is(fieldValue));
    return getMongoOperations().find(query, BarImpl.class);
} 

Saving a Bar works just fine, it would save it in mongo along with the "_class" attribute for both Foo and Bar. However, finding by some attribute in Foo would throw an exception like this:

Exception in thread "main" java.lang.IllegalArgumentException: No
property someField found on test.Foo!
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:225)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getPath(QueryMapper.java:202)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getTargetProperty(QueryMapper.java:190)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:86)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:486)

The solution that was given was to use the @TypeAlias annotation on the abstract class, which told the framework to use a specific implementation (in this case FooImpl).

In my case, I have interface members, instead of abstract members:

@Document(collection="myBeanBar")
public class BarImpl implements Bar {
    String id;
    IFoo foo;
    // More fields and methods ...
}

I'm very reluctant to put an annotation on the interface IFoo that will give a default implementation, instead I'd like to tell the framework what this field's default implementation in the context of the implementing BarImpl class, similar to @JsonTypeInfo:

@Document(collection="myBeanBar") 
public class BarImpl implements Bar {
    String id;    

    @JsonTypeInfo(use = Id.CLASS, defaultImpl = FooImpl.class)
    IFoo foo; 

    // More fields and methods ... 
}

I found this answer, which more or less says to avoid using interfaces. but I'd be happy to know if there's no better option.

Any ideas?

Thanks!


Source: (StackOverflow)

Spring Data - MongoDB indexing DBRef

I'm using spring-data-mongodb-1.2.0.RELEASE. I have two classes A and B where B has a reference to A and it is annotated with @DBRef.

Class A:

@Document(collection = "a")
public class A {
@Id
public String id;

/** The TicketGrantingTicket this is associated with. */
@Field
public String name;

public A(String id, String name) {
    this.id = id;
    this.name = name;
}
}

Class B:

@Document(collection = "b")
public class B {

@Id
public String id;

@Field
public String name;

@DBRef
@Indexed
public A a;

public B(String id, String name, A a) {
    super();
    this.id = id;
    this.name = name;
    this.a = a;
}
}

Since I'm quering for all instances of B that are refering to a certain A:

B fromDB = mongoOperations.findOne(Query.query(Criteria.where("a.$id").is(a1.id)), B.class);

I need it to be indexed.

After the first insertion of a B instance into MongoDB an index should be created. As can be seen below it doesn't:

Does anyone know how can I create such an index ?

In addition it looks like the DBRef filed (as can be seen by the mongo shell) does not match to the format as it is defined at MongoDB documentation.

Am I missing something here?


Source: (StackOverflow)

Spring data version annotation not incrementing when used on a mongo collection

I am using spring data with mongodb to store binary data such as images etc I want to maintain a version field to append to the url to cheat the browser from caching images.

See my document base class below:

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.mongodb.core.index.Indexed;

public abstract class BaseDocument {

    @Id
    @Indexed(unique=true)
    protected long id;
    protected byte[] data;
    protected String mimeType;
    protected String filename;
    protected String extension;
    @Version
    private Long version;

I also have a repository wrapping MongoOperations for saving my documents.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class DocumentRepository implements IDocumentRepository {

    @Autowired
    private MongoOperations mongoTemplate;

    @Override
    public <D extends BaseDocument> void saveDocument(D document) {
        mongoTemplate.save(document);
    }

In an attempt to implement versioning, I did some hunting around and found that there was a @Version annotation for spring mongo but that is was deprecated. I then discovered that the spring data @Version annotation should used instead. So I went ahead and used the spring data @Version annotation.

What I expect to happen is that my version field would be incremented every time I save my document. I am overwriting the same document several times but my version field is not getting incremented as I am expecting.

Am I doing something incorrectly or is there something additional that I need to do?


Source: (StackOverflow)

Set MongoDb converter programatically

I'm trying to use a custom converter with spring-data-mongodb. I want to create it programmatically, but I get the following error:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of     converting from type org.joda.time.LocalDate to type java.lang.String
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:475)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:154)
....
....

The following is the failing code snippet:

    Mongo mongo = new Mongo();
    MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongo, "database");

    List<Converter> converters = new ArrayList<>();
    converters.add(new LocalDateWriteConverter());
    converters.add(new LocalDateReadConverter());
    CustomConversions customConversions = new CustomConversions(converters);

    MappingContext mappingContext = new SimpleMongoMappingContext();
    MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(mongoDbFactory, mappingContext);
    mappingMongoConverter.setCustomConversions(customConversions);

    MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, mappingMongoConverter);

    MongoDbEvent mongoEvent = new MongoDbEvent(new LocalDate(2012, 12, 8));
    mongoTemplate.insert(mongoEvent);

And here are my converter classes:

class LocalDateReadConverter implements Converter<String, LocalDate> {
    @Override
    public LocalDate convert(String s) {
        // Conversion code omitted.
    }
}

class LocalDateWriteConverter implements Converter<LocalDate, String> {

    @Override
    public String convert(LocalDate localDate) {
        // Conversion code omitted.
    }
}

The class I'm trying to persist looks like this:

import org.joda.time.LocalDate;

public class MongoDbEvent {

    private String id;
    private LocalDate date;

    public MongoDbEvent(LocalDate date) {
        this.date = date;
    }

    public String getId() {
        return id;
    }

    public LocalDate getDate() {
        return date;
    }

    @Override
    public String toString() {
        return "MongoDbEvent{" +
                "id='" + id + '\'' +
                ", date=" + date +
                '}';
        }
}

Any suggestions would be much appreciated.

-Daniel


Source: (StackOverflow)

Mongos routing with ReadPreference=NEAREST

I'm having trouble diagnosing an issue where my Java application's requests to MongoDB are not getting routed to the Nearest replica, and I hope someone can help. Let me start by explaining my configuration.

The Configuration:

I am running a MongoDB instance in production that is a Sharded ReplicaSet. It is currently only a single shard (it hasn't gotten big enough yet to require a split). This single shard is backed by a 3-node replica set. 2 nodes of the replica set live in our primary data center. The 3rd node lives in our secondary datacenter, and is prohibited from becoming the Master node.

We run our production application simultaneously in both data centers, however the instance in our secondary data center operates in "read-only" mode and never writes data into MongoDB. It only serves client requests for reads of existing data. The objective of this configuration is to ensure that if our primary datacenter goes down, we can still serve client read traffic.

We don't want to waste all of this hardware in our secondary datacenter, so even in happy times we actively load balance a portion of our read-only traffic to the instance of our application running in the secondary datacenter. This application instance is configured with readPreference=NEAREST and is pointed at a mongos instance running on localhost (version 2.6.7). The mongos instance is obviously configured to point at our 3-node replica set.

From a mongos:

mongos> sh.status()
--- Sharding Status --- 
sharding version: {
"_id" : 1,
"version" : 4,
"minCompatibleVersion" : 4,
"currentVersion" : 5,
"clusterId" : ObjectId("52a8932af72e9bf3caad17b5")
}
shards:
{  "_id" : "shard1",  "host" : "shard1/failover1.com:27028,primary1.com:27028,primary2.com:27028" }
databases:
{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
{  "_id" : "test",  "partitioned" : false,  "primary" : "shard1" }
{  "_id" : "MyApplicationData",  "partitioned" : false,  "primary" : "shard1" }

From the failover node of the replicaset:

shard1:SECONDARY> rs.status()
{
"set" : "shard1",
"date" : ISODate("2015-09-03T13:26:18Z"),
"myState" : 2,
"syncingTo" : "primary1.com:27028",
"members" : [
{
    "_id" : 3,
    "name" : "primary1.com:27028",
    "health" : 1,
    "state" : 1,
    "stateStr" : "PRIMARY",
    "uptime" : 674841,
    "optime" : Timestamp(1441286776, 2),
    "optimeDate" : ISODate("2015-09-03T13:26:16Z"),
    "lastHeartbeat" : ISODate("2015-09-03T13:26:16Z"),
    "lastHeartbeatRecv" : ISODate("2015-09-03T13:26:18Z"),
    "pingMs" : 49,
    "electionTime" : Timestamp(1433952764, 1),
    "electionDate" : ISODate("2015-06-10T16:12:44Z")
},
{
    "_id" : 4,
    "name" : "primary2.com:27028",
    "health" : 1,
    "state" : 2,
    "stateStr" : "SECONDARY",
    "uptime" : 674846,
    "optime" : Timestamp(1441286777, 4),
    "optimeDate" : ISODate("2015-09-03T13:26:17Z"),
    "lastHeartbeat" : ISODate("2015-09-03T13:26:18Z"),
    "lastHeartbeatRecv" : ISODate("2015-09-03T13:26:18Z"),
    "pingMs" : 53,
    "syncingTo" : "primary1.com:27028"
},
{
    "_id" : 5,
    "name" : "failover1.com:27028",
    "health" : 1,
    "state" : 2,
    "stateStr" : "SECONDARY",
    "uptime" : 8629159,
    "optime" : Timestamp(1441286778, 1),
    "optimeDate" : ISODate("2015-09-03T13:26:18Z"),
    "self" : true
}
],
"ok" : 1
}


shard1:SECONDARY> rs.conf()
{
    "_id" : "shard1",
    "version" : 15,
    "members" : [
    {
        "_id" : 3,
        "host" : "primary1.com:27028",
        "tags" : {
            "dc" : "primary"
        }
    },
    {
        "_id" : 4,
        "host" : "primary2.com:27028",
        "tags" : {
            "dc" : "primary"
        }
    },
    {
        "_id" : 5,
        "host" : "failover1.com:27028",
        "priority" : 0,
        "tags" : {
            "dc" : "failover"
        }
    }
    ],
    "settings" : {
        "getLastErrorModes" : {"ACKNOWLEDGED" : {}}
    }
}

The Problem:

The problem is that requests which hit this mongos in our secondary datacenter seem to be getting routed to a replica running in our primary datacenter, not the nearest node, which is running in the secondary datacenter. This incurs a significant amount of network latency and results in bad read performance.

My understanding is that the mongos is deciding which node in the replica set to route the request to, and it's supposed to honor the ReadPreference from my java driver's request. Is there a command I can run in the mongos shell to see the status of the replica set, including ping times to nodes? Or some way to see logging of incoming requests which indicates the node in the replicaSet that was chosen and why? Any advice at all on how to diagnose the root cause of my issue?


Source: (StackOverflow)

How to reference nested object into other collection Mongodb

I want to reference nested object exist in another Collection object, in my Event object so that when i get Event of User than Venue of Event shall retrieve with it, i am new in mongodb and spring can any one help to do this.

class User{
private String name;
private Venue venue;

//Getter and Setter 
}

class Event {
@DBRef
private Venue venue;

//Getter and Setter 
}

Source: (StackOverflow)

spring data mongodb: access default POJO converter from within custom converter

I have spring data mongo custom converters setup via xml as follows

<mongo:mapping-converter id="mongoConverter" db-factory-ref="mongoDbFactory">
    <mongo:custom-converters>
        <mongo:converter ref="customWriteConverter" />
        <mongo:converter ref="customReadConverter" />
    </mongo:custom-converters>
</mongo:mapping-converter>

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

<bean id="customWriteConverter" class="package.WriteConverter" />
<bean id="customReadConverter" class="package.ReadConverter" />

In the custom read/write converter, I would like to re-use spring-data-mongo's default pojo converter to save certain properties as subdocuments.

consider a simplified example -

class A {
    B b;
    String var1;
    int var2;
}

class B {
    String var3;
    String var4;
}

I want to handle conversion of class A using customWriteConverter and customReadConverter, but in my custom converters I also want to delegate conversion of class B back to spring-data-mongo's default POJO converter.

How can I do this? I have not been able to successfully autowire a MongoConverter or MongoTemplate into the custom converter since the MongoConverter/MongoTemplate bean creation is in progress when it tries to create the custom converter. Is it possible to get access to the default converter and use that from within the custom converter?


Source: (StackOverflow)

Spring Data MongoDB Date between two Dates

i'm using Spring Data for MongoDB and got the following classes

class A {
    List<B> b;
}

class B {
    Date startDate;
    Date endDate;
}

when i save an object of A it gets persisted like

{
    "_id" : "DQDVDE000VFP8E39",
    "b" : [
          {
              "startDate" : ISODate("2009-10-05T22:00:00Z"),
              "endDate" : ISODate("2009-10-29T23:00:00Z")
          },
          {
              "startDate" : ISODate("2009-11-01T23:00:00Z"),
              "endDate" : ISODate("2009-12-30T23:00:00Z")
          }
    ]
}

Now i want to query the db for documents matching entries in b where a given date is between startDate and endDate.

Query query = new Query(Criteria.where("b").elemMatch(
    Criteria.where("startDate").gte(date)
    .and("endDate").lte(date)
);

Which results in the following mongo query:

{
   "b": {
       "$elemMatch": { 
           "startDate" : { "$gte" : { "$date" : "2009-11-03T23:00:00.000Z"}}, 
           "endDate" : { "$lte" : { "$date" : "2009-11-03T23:00:00.000Z"}}
       }
   }
}

but returns no resulting documents. Does anybody know what i'm doing wrong? I don't get it...

Thank you very much in advance!!


Source: (StackOverflow)

MongoDB Lifecycle event access to MongoTemplate

I'm trying to implement a versioning system for my mongodb documents with Spring Data Mongodb. I thought i'd take advantage of the Mongo lifecycle events

Mongo Lifecycle Events in Spring

What I wanted to do was listen to onBeforeSave and fetch the pristine version of the document, and get the diff between the two.

@Override
public void onBeforeSave(Table table, DBObject dbo) {

    if (table.getId() != null) {
        TableChange change = new TableChange();

        Table beforeTable = mongoOperations.findById(table.getId(), Table.class);

        if (!beforeTable.getName().equals(table.getName())) {
            change.setName(table.getName());
        }

        MapDifference<String, Column> diff = Maps.difference(beforeTable.getColumns(), table.getColumns());

        logger.debug(diff.entriesInCommon().toString());
        logger.debug(diff.entriesDiffering().toString());
        logger.debug(diff.entriesOnlyOnLeft().toString());
        logger.debug(diff.entriesOnlyOnRight().toString());         

        table.addChange(change);
    }
}

The problem I'm having is that i can't get a reference to mongoOperations. It keeps creating a circular reference. Whether i @Autowire:

Autowire Injection

Mongo config:

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
    <constructor-arg name="mongoConverter" ref="fooConverter" />
    <property name="writeResultChecking" value="EXCEPTION" />
</bean>

<bean class="com.example.listener.document.TableListener"></bean>

Listener:

public class TableListener extends AbstractMongoEventListener<Table> {

    private static final Logger logger = LoggerFactory.getLogger(TableListener.class);

    @Autowired MongoTemplate mongoTemplate;

    @Override
    public void onBeforeSave(Table table, DBObject dbo) {
        // .... 
    }
}

or use Setter Injection

Setter Injection

Mongo config:

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/>
    <constructor-arg name="mongoConverter" ref="fooConverter" />
    <property name="writeResultChecking" value="EXCEPTION" />
</bean>

<bean class="com.example.listener.document.TableListener">
    <property name="mongoTemplate" ref="mongoTemplate" />
</bean>

Listener:

public class TableListener extends AbstractMongoEventListener<Table> {

    private static final Logger logger = LoggerFactory.getLogger(TableListener.class);

    private MongoTemplate mongoTemplate;

    public void setMongoTemplate(MongoTemplate mongoTemplate) {
        this.mongoTemplate = mongoTemplate;
    }

    @Override
    public void onBeforeSave(Table table, DBObject dbo) {
        // .... 
    }
}

It makes sense to me to handle the Document versioning in the lifecycle events. I did a similar thing with PHP/Doctrine/Mongo

How I did it with Doctrine/PHP

In the case of Doctrine I get a reference to the Document Manager in the lifecycle callback. Any clues how i can do this same thing with Spring Data?


Source: (StackOverflow)

Missing class org.springframework.objenesis.ObjenesisStd

I am trying to use Spring Data for MongoDB. I am using full text search feature of MongoDB, and wanted to try Spring Data annotations for text index fields (@TextIndexed). This feature is available in 1.6.0.BUILD-SNAPSHOT of Spring Data MongoDB.

I am trying to setup simple application context in Spring and to run simple JUnit test. However my application context loading fails since I changed 1.5.1.RELEASE to 1.6.0.BUILD-SNAPSHOT.

The error which I am getting is below:

Caused by: org.springframework.beans.BeanInstantiationException: Could
  not instantiate bean class
  [org.springframework.data.mongodb.core.MongoTemplate]: Constructor
  threw exception; nested exception is java.lang.NoClassDefFoundError:
  org/springframework/objenesis/ObjenesisStd at
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163) at
  org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121) at
  org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
    ... 51 more Caused by: java.lang.NoClassDefFoundError:
  org/springframework/objenesis/ObjenesisStd at
  org.springframework.data.mongodb.core.convert.DefaultDbRefResolver.<init>(DefaultDbRefResolver.java:72) at
  org.springframework.data.mongodb.core.MongoTemplate.getDefaultMongoConverter(MongoTemplate.java:1961) at
  org.springframework.data.mongodb.core.MongoTemplate.<init>(MongoTemplate.java:210) at
  org.springframework.data.mongodb.core.MongoTemplate.<init>(MongoTemplate.java:174) at 
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at 
  java.lang.reflect.Constructor.newInstance(Constructor.java:513) at
  org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
    ... 53 more Caused by: java.lang.ClassNotFoundException:
  org.springframework.objenesis.ObjenesisStd at
  java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
  java.security.AccessController.doPrivileged(Native Method) at
  java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
  java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
  sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
  java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Now, I tried to figure out which JAR contains org.springframework.objenesis.ObjenesisStd by using grepcode.com, but it can't return any Spring related JARs.

What am I missing here?


Source: (StackOverflow)

Spring data mongodb auditing not working.. (Java config)

i'm currently using Spring data mongodb 1.6.0-RELEASE and i know it has auditing feature. I put @EnableMongoAuditing annotation on top of my configuration class. And my bean is below:

@Document
public class MyBean{

@Id
private AnotherCustomBean anotherCustomBean = new AnotherCustomBean();

@CreatedDate
private Date creationDate;

@LastModifiedDate
private Date lastModifiedDate;

.
.
.

When i save this bean with mongoTemplate.save(myBean); it's not setting created date and last modified date...And it has no errors.

Any help would be appreciated,

Thanks.


Source: (StackOverflow)