
The Payara Monthly Catch -September 2025
Welcome aboard the September issue of The Monthly Catch! With summer holidays wrapping up, the Java world is back […]
Managing configurations in enterprise Java application can often feel like a daunting task. As applications scale, configuration values become scattered across multiple files, formats, and environments—creating complexity and increasing the risk of errors. From juggling different settings for development, testing and production environments to dealing with the frustration of restarting applications for minor config changes, these challenges slow down development and impact productivity.
But what if there was a better way to manage configurations that are flexible, dynamic and type-safe? This Nugget Friday, we discuss MicroProfile Config—a powerful, standards-based solution designed to simplify configuration management for Java EE and Jakarta EE applications.
Configuration management in non-trivial enterprise Java applications has long presented a range of challenges, including:
For example, consider a traditional approach that involves reading from a properties file:
public class DatabaseConfig {
public static String getDbUrl() {
Properties props = new Properties();
try (InputStream is = DatabaseConfig.class.getResourceAsStream("/config.properties")) {
props.load(is);
} catch (IOException e) {
throw new RuntimeException("Failed to load config", e);
}
return props.getProperty("db.url");
}
}
This approach is prone to errors, not type-safe and doesn’t easily support multiple configuration sources or dynamic updates. Moreover, the configuration properties are tightly coupled to the application.
MicroProfile Config, part of the MicroProfile project, addresses these issues by providing a unified way to handle configuration in Java EE and Jakarta EE applications. It addresses the above issues with a flexible, extensible and standards-based approach.
Here’s how you can access configuration using MicroProfile Config:
@Inject
@ConfigProperty(name = "db.url")
private String dbUrl;
Or for programmatic access:
@Inject
private Config config;
public String getDbUrl() {
return config.getValue("db.url", String.class);
}
MicroProfile Config operates on the principle of configuration sources and priorities, offering powerful features. Here’s everything you need to understand the MicroProfile Config API:
Switching to MicroProfile Config provides a host of benefits that directly address the pain points of traditional configuration management. In particular:
MicroProfile Config allows you to create custom configuration sources. For example, you can source configurations from a database for database-stored configurations:
public class DatabaseConfigSource implements ConfigSource {
@Inject
AmazingDatabaseService dbService;
@Override
public Map<String, String> getProperties() {
return dbService.loadProps();
}
@Override
public String getValue(String propertyName) {
return dbService.getPropertyValue(propertyName);
}
@Override
public String getName() {
return "Database Config Source";
}
}
You can also implement custom type conversions:
@Priority(100)
public class CustomTypeConverter implements Converter<CustomType> {
@Override
public CustomType convert(String value) {
// Convert string to CustomType
}
While MicroProfile Config offers many advantages, there are a few considerations to keep in mind:
MicroProfile Config simplifies configuration management in Java EE and Jakarta EE applications. It provides a unified API that works across different environments, making your applications more adaptable. With MicroProfile Config, you can handle type-safe configurations, making your code safer. You can easily adapt your applications to different deployment scenarios, improving flexibility. MicroProfile Config is a solid choice for your configuration needs, whether you’re working on microservices, cloud-native applications or traditional enterprise systems. Start integrating it into your projects today and enjoy smoother, more reliable configuration management.
Remember to use its advanced features and keep security in mind when handling sensitive data. Happy Nugget Friday! Happy Coding!
Share:
Welcome aboard the September issue of The Monthly Catch! With summer holidays wrapping up, the Java world is back […]
We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]
If your Java EE 8 applications run on Red Hat JBoss Enterprise Application Platform (EAP) 7, you can’t afford […]
Hi, how to load different MicroProfile config values based on active Maven profile?
Hi Tadas, that’s a good question. I’ll give you a detailed answer as blog post that should be published this Friday. The answer should be relevant to others as well. So I’ll share in a blog post. Stay tuned. Cheers and thanks for visiting us.