【问题标题】:Set comment for every queries ran by Spring Data为 Spring Data 运行的每个查询设置注释
【发布时间】:2017-09-25 15:40:06
【问题描述】:

Spring 应用程序完成的所有 MongoDB 查询都必须有注释,现在这是通过调用 org.springframework 上的方法 comment 来完成的.data.mongodb.core.query.Query.

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

这意味着我必须使用 MongoTemplate 对象来进行所有查询,并且我正在失去 Spring Data 提供的抽象(我必须改为实现该方法只是声明它)。

有没有办法配置 Spring Data 为每个查询应用一个函数(设置注释)?

谢谢

【问题讨论】:

    标签: java spring mongodb spring-data


    【解决方案1】:

    看起来您可以通过 AOP 实现所需的行为。 网上应该有很多样例,例如:Stack Overflow: How to Instrument Advice a Spring Data JPA Repository

    【讨论】:

    • 这看起来不正确,除非你知道如何访问通过 AOP 生成的 Query 对象?
    猜你喜欢
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 2015-04-16
    • 2013-05-02
    • 2013-07-20
    • 2023-02-13
    • 1970-01-01
    • 2021-08-05
    相关资源
    最近更新 更多