CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-quarkus--quarkus-core

Quarkus core components - runtime library for the Cloud Native, Container First Java framework

Pending
Overview
Eval results
Files

configuration.mddocs/

Configuration System

The Configuration System provides comprehensive configuration management with annotations, type converters, and runtime configuration support for Quarkus applications.

Configuration Annotations

Configuration Root

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ConfigRoot {
    /**
     * Configuration phase when this root is available.
     * @return Configuration phase
     */
    ConfigPhase phase() default ConfigPhase.RUNTIME_INIT;
    
    /**
     * Configuration prefix (deprecated).
     * @return Configuration prefix
     */
    @Deprecated
    String prefix() default "";
    
    /**
     * Configuration name (deprecated).
     * @return Configuration name
     */
    @Deprecated
    String name() default "";
}

Configuration Item

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface ConfigItem {
    /**
     * Property name override.
     * @return Property name, empty string uses field name
     */
    String name() default "";
    
    /**
     * Default value for the configuration property.
     * @return Default value
     */
    String defaultValue() default "";
    
    /**
     * Whether to include this item in generated documentation.
     * @return true to include in docs
     */
    boolean generateDocumentation() default true;
}

Configuration Group

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ConfigGroup {
    // Groups related configuration items together
}

Configuration Phases

public enum ConfigPhase {
    /**
     * Available at build time only.
     */
    BUILD_TIME,
    
    /**
     * Available at runtime initialization.
     */
    RUNTIME_INIT,
    
    /**
     * Available during bootstrap phase.
     */
    BOOTSTRAP
}

Type Converters

Duration Converter

public class DurationConverter implements Converter<Duration> {
    /**
     * Convert string to Duration.
     * Supports formats like: "10s", "5m", "2h", "1d"
     * @param value String representation
     * @return Duration object
     */
    @Override
    public Duration convert(String value) throws IllegalArgumentException, NullPointerException;
}

Memory Size Types

public final class MemorySize {
    /**
     * Create MemorySize from bytes.
     * @param bytes Size in bytes
     */
    public MemorySize(long bytes);
    
    /**
     * Get size in bytes.
     * @return Size in bytes
     */
    public long getBytes();
    
    /**
     * Parse memory size from string.
     * Supports formats like: "10MB", "512KB", "2GB"
     * @param input String representation
     * @return MemorySize object
     */
    public static MemorySize parse(String input);
    
    /**
     * String representation in bytes.
     * @return String representation
     */
    public String toString();
    
    /**
     * Human-readable string representation.
     * @return Human-readable format
     */
    public String toHumanReadableString();
}

public class MemorySizeConverter implements Converter<MemorySize> {
    /**
     * Convert string to MemorySize.
     * @param value String representation (e.g., "10MB", "512KB")
     * @return MemorySize object
     */
    @Override
    public MemorySize convert(String value) throws IllegalArgumentException, NullPointerException;
}

Path Converter

public class PathConverter implements Converter<Path> {
    /**
     * Convert string to Path.
     * @param value String path representation
     * @return Path object
     */
    @Override
    public Path convert(String value) throws IllegalArgumentException, NullPointerException;
}

Network Address Converter

public class InetAddressConverter implements Converter<InetAddress> {
    /**
     * Convert string to InetAddress.
     * @param value IP address or hostname
     * @return InetAddress object
     */
    @Override
    public InetAddress convert(String value) throws IllegalArgumentException, NullPointerException;
}

Configuration Exception

public class ConfigurationException extends RuntimeException {
    /**
     * Create configuration exception with message.
     * @param message Error message
     */
    public ConfigurationException(String message);
    
    /**
     * Create configuration exception with message and cause.
     * @param message Error message
     * @param cause Root cause
     */
    public ConfigurationException(String message, Throwable cause);
}

Usage Examples

Basic Configuration Root

import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;

@ConfigRoot(phase = ConfigPhase.RUNTIME_INIT)
public class DatabaseConfig {
    
    /**
     * Database URL.
     */
    @ConfigItem(defaultValue = "jdbc:h2:mem:test")
    public String url;
    
    /**
     * Database username.
     */
    @ConfigItem(defaultValue = "sa")
    public String username;
    
    /**
     * Database password.
     */
    @ConfigItem
    public String password;
    
    /**
     * Maximum pool size.
     */
    @ConfigItem(defaultValue = "10")
    public int maxPoolSize;
    
    /**
     * Connection timeout.
     */
    @ConfigItem(defaultValue = "30s")
    public Duration connectionTimeout;
}

Configuration properties (application.properties):

database.url=jdbc:postgresql://localhost:5432/mydb
database.username=user
database.password=secret
database.max-pool-size=20
database.connection-timeout=45s

Configuration with Groups

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.ConfigPhase;

@ConfigRoot(phase = ConfigPhase.RUNTIME_INIT)
public class ServerConfig {
    
    /**
     * HTTP server configuration.
     */
    @ConfigItem
    public HttpConfig http;
    
    /**
     * SSL configuration.
     */
    @ConfigItem
    public SslConfig ssl;
}

@ConfigGroup
public static class HttpConfig {
    
    /**
     * HTTP port.
     */
    @ConfigItem(defaultValue = "8080")
    public int port;
    
    /**
     * HTTP host.
     */
    @ConfigItem(defaultValue = "localhost")
    public String host;
    
    /**
     * Request timeout.
     */
    @ConfigItem(defaultValue = "30s")
    public Duration timeout;
}

@ConfigGroup
public static class SslConfig {
    
    /**
     * Enable SSL.
     */
    @ConfigItem(defaultValue = "false")
    public boolean enabled;
    
    /**
     * SSL port.
     */
    @ConfigItem(defaultValue = "8443")
    public int port;
    
    /**
     * Keystore path.
     */
    @ConfigItem
    public Optional<Path> keystore;
}

Configuration properties:

server.http.port=9090
server.http.host=0.0.0.0
server.http.timeout=60s
server.ssl.enabled=true
server.ssl.port=9443
server.ssl.keystore=/path/to/keystore.p12

Custom Type Converters

import java.util.regex.Pattern;
import org.eclipse.microprofile.config.spi.Converter;

// Custom converter for email addresses
public class EmailConverter implements Converter<Email> {
    private static final Pattern EMAIL_PATTERN = 
        Pattern.compile("^[A-Za-z0-9+_.-]+@([A-Za-z0-9.-]+\\.[A-Za-z]{2,})$");
    
    @Override
    public Email convert(String value) {
        if (value == null || value.trim().isEmpty()) {
            return null;
        }
        
        if (!EMAIL_PATTERN.matcher(value).matches()) {
            throw new IllegalArgumentException("Invalid email format: " + value);
        }
        
        return new Email(value);
    }
}

// Email type
public class Email {
    private final String address;
    
    public Email(String address) {
        this.address = address;
    }
    
    public String getAddress() {
        return address;
    }
    
    @Override
    public String toString() {
        return address;
    }
}

// Configuration using custom converter
@ConfigRoot(phase = ConfigPhase.RUNTIME_INIT)
public class NotificationConfig {
    
    /**
     * Admin email address.
     */
    @ConfigItem(defaultValue = "admin@example.com")
    public Email adminEmail;
    
    /**
     * Support email address.
     */
    @ConfigItem
    public Optional<Email> supportEmail;
}

Memory Size Configuration

import io.quarkus.runtime.configuration.MemorySize;

@ConfigRoot(phase = ConfigPhase.RUNTIME_INIT)
public class CacheConfig {
    
    /**
     * Maximum cache size.
     */
    @ConfigItem(defaultValue = "64MB")
    public MemorySize maxSize;
    
    /**
     * Initial cache size.
     */
    @ConfigItem(defaultValue = "8MB")
    public MemorySize initialSize;
}

Configuration properties:

cache.max-size=128MB
cache.initial-size=16MB

Usage:

@Inject
CacheConfig cacheConfig;

public void setupCache() {
    long maxBytes = cacheConfig.maxSize.getBytes();
    long initialBytes = cacheConfig.initialSize.getBytes();
    
    System.out.println("Max cache size: " + cacheConfig.maxSize.toHumanReadableString());
    System.out.println("Initial cache size: " + cacheConfig.initialSize.toHumanReadableString());
}

Build-Time Configuration

@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
public class BuildTimeConfig {
    
    /**
     * Enable debug information in build.
     */
    @ConfigItem(defaultValue = "false")
    public boolean debug;
    
    /**
     * Build optimization level.
     */
    @ConfigItem(defaultValue = "O2")
    public String optimizationLevel;
    
    /**
     * Build artifacts directory.
     */
    @ConfigItem(defaultValue = "target")
    public Path artifactsDir;
}

Configuration Injection

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@ApplicationScoped
public class DatabaseService {
    
    @Inject
    DatabaseConfig config;
    
    public void connect() {
        try {
            Connection connection = DriverManager.getConnection(
                config.url, 
                config.username, 
                config.password
            );
            
            // Configure connection pool
            configurePool(connection, config.maxPoolSize, config.connectionTimeout);
            
        } catch (SQLException e) {
            throw new ConfigurationException("Failed to connect to database", e);
        }
    }
    
    private void configurePool(Connection connection, int maxSize, Duration timeout) {
        // Pool configuration logic
    }
}

Configuration Profiles

Configuration can vary by profile (dev, test, prod):

# Default configuration
server.port=8080
database.url=jdbc:h2:mem:test

# Development profile
%dev.server.port=8081
%dev.database.url=jdbc:h2:mem:dev

# Test profile  
%test.server.port=0
%test.database.url=jdbc:h2:mem:test

# Production profile
%prod.server.port=80
%prod.database.url=jdbc:postgresql://prod-db:5432/app

Access current profile:

import io.quarkus.runtime.LaunchMode;

LaunchMode mode = LaunchMode.current();
String profile = mode.getDefaultProfile(); // "dev", "test", or "prod"

Install with Tessl CLI

npx tessl i tessl/maven-io-quarkus--quarkus-core

docs

application-lifecycle.md

build-time.md

configuration.md

index.md

logging.md

native-image.md

runtime-context.md

tile.json