Datastax Java driver 4.6.1无法使用application.conf覆盖配置。

huangapple go评论78阅读模式
英文:

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

问题

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

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

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

有什么想法是怎么回事,或者我如何检查是否应用了自定义属性?

英文:

I have created application.conf in my src.main.resources folder:

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?

答案1

得分: 1

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

英文:

If you use Maven then you've placed it correctly in the src/main/resources folder. Otherwise, it needs to go in the application classpath.

答案2

得分: 1

@ThatHansel,

你能展示类似下面的输出结果以了解你从程序中获得了什么值吗?

我有一个使用 DataStax Java Driver 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
英文:

@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. 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 (i.e. idempotence being true & timeout being 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

huangapple
  • 本文由 发表于 2020年10月15日 09:54:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64363794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定