简体   繁体   English

Datastax Java 驱动程序 4.6.1 无法使用 application.conf 覆盖配置

[英]Datastax Java driver 4.6.1 unable to override configurations with application.conf

I have created application.conf in my src.main.resources folder:我在 src.main.resources 文件夹中创建了 application.conf:

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

These are just some test properties, and I don't think these properties are being applied because when I poke around in the debugger the defaults are unchanged.这些只是一些测试属性,我认为没有应用这些属性,因为当我在调试器中浏览时,默认值没有改变。

Any ideas what could be going on or how I can check if the custom properties are being applied?任何想法可能会发生什么或者我如何检查是否正在应用自定义属性?

If you use Maven then you've placed it correctly in the src/main/resources folder.如果您使用 Maven,那么您已将其正确放置在src/main/resources文件夹中。 Otherwise, it needs to go in the application classpath.否则,它需要进入应用程序类路径。

@ThatHansel, @ThatHansel,

Could you show the output similar to the below to understand what values you get from your program?您能否显示类似于以下内容的输出以了解您从程序中获得的值?

I've a sample class leveraging DataStax Java Driver 4.9.0 and I am printing the values.我有一个利用 DataStax Java Driver 4.9.0的示例类,我正在打印这些值。 I am using the defaults here for this demonstration.我在此演示中使用默认值。

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));
    }
    }
}

and when I run this program I get the below and you should also see something similar in your case (ie idempotence being true & timeout being PT5S ),当我运行这个程序时,我得到下面的结果,你也应该在你的情况下看到类似的东西(即幂等性为,超时为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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM