I'm using config loader from file like below but driver doesn't see environment variable from config and throws com.datastax.oss.driver.api.core.auth.AuthenticationException: Authentication error on node /105.0.153.68:9042: server replied with 'Provided username ${CASSANDRA_USR} and/or password are incorrect' to AuthResponse request
How can I solve this problem?
Java code
File confFile = new File("config/application.properties");
CqlSessionBuilder builder = CqlSession.builder();
builder.withConfigLoader(DriverConfigLoader.fromFile(confFile));
CqlSession session = builder.build();
application.properties
...
datastax-java-driver.advanced.auth-provider.class=PlainTextAuthProvider
datastax-java-driver.advanced.auth-provider.username=${CASSANDRA_USR}
datastax-java-driver.advanced.auth-provider.password=${CASSANDRA_PWD}
datastax-java-driver.advanced.protocol.version=V4
...
Environment variable substitution only works with HOCON (application.conf
). If you use standard Java properties, ${CASSANDRA_USR}
is interpreted as a literal string.
If switching to HOCON is not an option, you can use a system property override in the command that starts the Java VM:
java -Ddatastax-java-driver.advanced.auth-provider.username=${CASSANDRA_USR} ...