Annotation Interface StaticInitSafe


@Target({TYPE,FIELD,PARAMETER}) @Retention(RUNTIME) @Documented public @interface StaticInitSafe
Used to mark a configuration object as safe to be initialized during the STATIC INIT phase.

The target configuration objects include ConfigSource, ConfigSourceProvider, ConfigSourceFactory and ConfigMapping. Moreover, this annotation can be used for ConfigProperty injection points.

When a Quarkus application is starting up, Quarkus will execute first a static init method which contains some extensions actions and configurations. Example:

 // Auto Generated by Quarkus
 public class Application {
     static {
         Config config = ConfigProvider.getConfig();
         String url = config.getValue("database.url", String.class);
         String login = config.getValue("database.login", String.class);
         String password = config.getValue("database.password", String.class);

         initDatabase(url, login, password);
     }
 }
 
Please check Initializing Fields for more information about static blocks. Since Config initializes first, some ConfigSources may not be suited to be initialized at static init. Consider the previous code example and a ConfigSource that requires database access. In this case, it is impossible to properly initialize such ConfigSource, because the database services are not yet available so the ConfigSource in unusable.