GuicedEE Config is a MicroProfile Config implementation. It follows the MicroProfile Config specification for configuration lookups, CDI-based injection, type conversion, and config source ordering. Environment variables, system properties, and standard META-INF/microprofile-config.properties files are supported, with an optional bridge for .env files used in development.
Key points
- Standards-compliant: org.eclipse.microprofile.config APIs and annotations
- CDI-friendly: inject values using
@ConfigPropertyand@Inject Config - Deterministic sources and priorities: Env vars, System props, and classpath
microprofile-config.properties - Type-safe conversion via MicroProfile
Converter<T>SPI
<dependency>
<groupId>com.guicedee</groupId>
<artifactId>guiced-config</artifactId>
</dependency>
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.inject.ConfigProperty;
public class MessagingService {
@Inject
@ConfigProperty(name = "messaging.enabled", defaultValue = "true")
boolean enabled;
@Inject
@ConfigProperty(name = "messaging.bootstrap.servers")
String bootstrapServers;
public void start() {
if (enabled) {
// use bootstrapServers
}
}
}
import jakarta.inject.Inject;
import org.eclipse.microprofile.config.Config;
public class HealthProbe {
@Inject
Config config;
public int livenessPort() {
return config.getOptionalValue("liveness.port", Integer.class).orElse(8081);
}
}
MicroProfile Config defines a composite of sources with numeric ordinals. Higher ordinal wins when keys overlap. Typical built-in order:
- Environment Variables (e.g.,
MESSAGING_ENABLED) — high ordinal - System Properties (e.g.,
-Dmessaging.enabled=true) - Classpath resources
META-INF/microprofile-config.properties
Additional notes
- Development convenience: this module can bridge a local
.envfile into the config system; values appear as MicroProfile properties but must not be committed to VCS. - Secrets: prefer environment variables or your CI secret manager; do not store secrets in
microprofile-config.properties.
MicroProfile Config converts common types automatically (boolean, int, Duration, etc.). You can register custom converters via SPI.
// Converter implementation
import org.eclipse.microprofile.config.spi.Converter;
public class MemorySizeConverter implements Converter<java.time.Duration> {
@Override
public java.time.Duration convert(String value) {
// example only — parse "10s" or "500ms"
if (value.endsWith("ms")) return java.time.Duration.ofMillis(Long.parseLong(value.replace("ms", "")));
if (value.endsWith("s")) return java.time.Duration.ofSeconds(Long.parseLong(value.replace("s", "")));
throw new IllegalArgumentException("Unsupported duration format: " + value);
}
}
// Register via ServiceLoader
// file: META-INF/services/org.eclipse.microprofile.config.spi.Converter
// your.pkg.MemorySizeConverter
- Defaults: use
@ConfigProperty(defaultValue = "...")for safe fallbacks. - Namespaces: group related keys with a common prefix (e.g.,
messaging.ordb.). This keepsmicroprofile-config.propertiesreadable. - Profiles: if your runtime supports MicroProfile profiles (e.g.,
mp.config.profile), profile-specific files likemicroprofile-config-dev.propertiescan override defaults. Treat this as optional; consult GUIDES for the chosen approach in this repository.
Place one or more microprofile-config.properties files on the classpath under META-INF/:
# META-INF/microprofile-config.properties
messaging.enabled=true
messaging.bootstrap.servers=localhost:9092
liveness.port=8081
- JPMS-friendly; the implementation exposes MicroProfile Config services via ServiceLoader.
- If you ship custom
Converter<T>orConfigSourceimplementations, register them underMETA-INF/servicesand add JPMSprovides ... with ...entries if your module is named.
- Pact:
PACT.md - Rules:
RULES.md - Guides:
GUIDES.md(see the configuration guide and secrets policy) - Architecture:
docs/architecture/README.md - MicroProfile Config Spec: https://github.com/eclipse/microprofile-config
- License: Apache 2.0
- PRs welcome; keep docs updated. When adding new configuration keys, also update
.env.example, the configuration guide, and any CI references.