Falydoor
Falydoor

Reputation: 462

Set comment for every queries ran by Spring Data

All MongoDB queries done by the Spring app must have a comment, right now this is done by calling the method comment on org.springframework.data.mongodb.core.query.Query.

public <T> T findOne(Query query, Class<T> klass) {
    query.comment("my comment");
    return mongoTemplate.findOne(query, klass);
}

That means I have to use the MongoTemplate object for making all my queries and I'm loosing the abstraction provided by Spring Data (I have to implement the method instead of just declaring it).

Is there a way to configure Spring Data to apply a function (that will set the comment) for every queries ?

Thank you

Upvotes: 2

Views: 1217

Answers (1)

Ivan
Ivan

Reputation: 847

It looks like you may achive the required behaviour by means of AOP. There should be a lot of samples over the internet, for example: Stack Overflow: How to Instrument Advice a Spring Data JPA Repository

Upvotes: 1

Related Questions