java - Spring Boot 不记录 CQL 查询

标签 java spring hibernate spring-boot cassandra

我在 Spring Boot 项目中使用 Spring Boot Data Cassandra,我正在尝试记录 CQL 查询,但将 spring.jpa.show-sql 设置为 true 不起作用。 这是我的 application.properties

spring.data.cassandra.keyspace-name=sample
spring.data.cassandra.contact-points=127.0.0.1
spring.data.cassandra.port=9042
spring.data.cassandra.schema-action=CREATE_IF_NOT_EXISTS
spring.jpa.show-sql=true

最佳答案

可以使用 LatencyTracker

@SpringBootApplication
public class Application implements CommandLineRunner {

    @Autowired
    public Application(Cluster cluster) {
        this.cluster = cluster;
    }

    @Override
    public void run(String... strings) throws Exception {

    cluster.register(new LatencyTracker() {
                @Override
                public void update(Host host, Statement statement, Exception exception, long newLatencyNanos) {
                    System.out.println(statement);
                }

                @Override
                public void onRegister(Cluster cluster) {

                }

                @Override
                public void onUnregister(Cluster cluster) {

                }
            });
    }

}

关于java - Spring Boot 不记录 CQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44358908/

相关文章:

java - JScrollPane 和 JList 自动滚动

java - 在 Java 中处理相同类型的不同异常?

java - Java 最大成对乘积

java - 监控和限制 Cloud Foundry Java 应用程序的内存使用情况

spring - 我无法更新 spring data neo4j 版本

java - Spring AMQP 的 "Cannot convert value of type"异常

java - Hibernate 反向一对多映射似乎无法正确处理从 Java 列表中删除项目

java - HTTPUrlConnection 为 Linux 返回 400 但适用于 Windows

mysql - Spring data JPA 存储库按条件排序

java - 使用 hibernate 以编程方式验证架构