【问题标题】:Datastax Java driver 4.6.1 unable to override configurations with application.confDatastax Java 驱动程序 4.6.1 无法使用 application.conf 覆盖配置
【发布时间】:2021-01-29 11:29:17
【问题描述】:

我在我的 src.main.resources 文件夹中创建了 application.conf:

datastax-java-driver {
  basic {
    request {
      default-idempotence = true
      timeout = 5
    }
  }
  advanced {
    connection {
      max-requests-per-connection = 32767
    }
  }
}

这些只是一些测试属性,我认为这些属性没有被应用,因为当我在调试器中四处寻找时,默认值没有改变。

任何想法可能发生什么或如何检查自定义属性是否正在应用?

【问题讨论】:

    标签: java spring spring-boot cassandra datastax


    【解决方案1】:

    如果您使用 Maven,那么您已将其正确放置在 src/main/resources 文件夹中。否则,它需要进入应用程序类路径。

    【讨论】:

      【解决方案2】:

      @ThatHansel,

      您能否显示类似于下面的输出以了解您从程序中获得的值?

      我有一个利用 DataStax Java 驱动程序4.9.0 的示例类,我正在打印这些值。我在此演示中使用默认设置。

      import java.net.InetSocketAddress;
      
      import com.datastax.oss.driver.api.core.CqlSession;
      import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
      
      public class DriverConfigsDemo {
          public static void main(String... args) {
          try (CqlSession session = CqlSession.builder().addContactPoint(new InetSocketAddress("localhost", 9042))
              .withLocalDatacenter("dc1").build()) {// update to match your environment
              System.out.println("Driver Configs - Idempotence: " + session.getContext().getConfig().getDefaultProfile().getString(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE));
              System.out.println("Driver Configs -     Timeout: " + session.getContext().getConfig().getDefaultProfile().getDuration(DefaultDriverOption.REQUEST_TIMEOUT));
          }
          }
      }
      

      当我运行这个程序时,我得到以下信息,您还应该在您的情况下看到 类似 (即幂等性为 true 和超时为 PT5S),

      09:56:10.019 [main] INFO  c.d.o.d.i.c.DefaultMavenCoordinates - DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.9.0
      09:56:10.574 [s0-admin-0] INFO  c.d.o.d.internal.core.time.Clock - Using native clock for microsecond precision
      Driver Configs - Idempotence: false
      Driver Configs -     Timeout: PT2S
      

      【讨论】:

        猜你喜欢
        • 2020-06-14
        • 1970-01-01
        • 2014-06-11
        • 2016-05-30
        • 2016-11-29
        • 2016-11-29
        • 2014-09-19
        • 2013-10-19
        • 2015-10-01
        相关资源
        最近更新 更多