1

I followed this documentation to get configs from application.properties in a quarkus service.

I am not using CDI, so here is what I am doing to get this config:

application.properties

redis.hosts=${REDIS_HOSTS}
redis.port=${REDIS_PORT}
redis.password=${REDIS_PASSWORD}

Note: I have set these environment variables.

RedisConfigInterface

import java.util.Set;
import io.smallrye.config.ConfigMapping;

@ConfigMapping(prefix = "redis")
interface RedisConfigInterface {
    Set<String> hosts();

    Integer port();

    String password();
}

ConfigCreation

public class ConfigCreation {
            
    public ConfigCreation() {
    
        //Registering config
        new SmallRyeConfigBuilder()
            .withMapping(RedisConfigInterface.class)
            .build();
        
        // Getting config
        RedisConfigInterface config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).getConfigMapping(RedisConfigInterface.class);
        
        
        Integer port = config.port();
        System.out.println(port);
    }
}

It builds correctly but I got this error when executing the service:

12:17:02 ERROR [io.qu.ru.Application] (Quarkus Main Thread)  Failed to start application (with profile dev): io.smallrye.config.ConfigValidationException: Configuration validation failed:
    java.util.NoSuchElementException: SRCFG00014: The config property redis.hosts is required but it could not be found in any config source
    java.util.NoSuchElementException: SRCFG00014: The config property redis.password is required but it could not be found in any config source
    java.util.NoSuchElementException: SRCFG00014: The config property redis.port is required but it could not be found in any config source

Am I missing something here? Everything seems to be set correctly.

Luiz Henrique
  • 877
  • 8
  • 25

0 Answers0