package org.palomafp.aadd.jaec.config; import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class Configuracion { private static final String RUTA_FICHERO_CONFIGURACION = "application.properties"; private static final Properties PROPIEDADES = new Properties(); // Constructor privado: de esta manera conseguimos que esta clase no se pueda // instanciar private Configuracion() { } // Cargamos el fichero de configuracion static { try (InputStream input = Configuracion.class.getClassLoader().getResourceAsStream(RUTA_FICHERO_CONFIGURACION)) { if (input == null) { throw new IOException("No se encuentra " + RUTA_FICHERO_CONFIGURACION + " en el classpath"); } PROPIEDADES.load(input); } catch (IOException e) { throw new RuntimeException("No se pudo cargar el fichero de configuración", e); } } // Metodo para obtener el valor de una propiedad public static String get(String clave) { String valor = PROPIEDADES.getProperty(clave); if (valor == null || valor.trim().isEmpty()) { throw new IllegalArgumentException("No existe la propiedad: " + clave); } return valor.trim(); } }