En mi aplicación Springboot, quiero usar @Value para leer alguna configuración, pero esta configuración se usa en muchos otros métodos, por lo que quiero definir la clave de configuración como una constante. Este es el código:
@Component public class InstanceConfig { private static final String CONFIGURE_KEY = "SUPPORT_MANAGER_PLANE_INSTANCES"; @Value("${SUPPORT_MANAGER_PLANE_INSTANCES}") private String supportManageInstances; @ApolloConfigChangeListener(value = ConfigConsts.NAMESPACE_APPLICATION) public void processConfigureChange(ConfigChangeEvent event) { log.info("configure changed do somthing"); ConfigChange configChange = event.getChange("SUPPORT_MANAGER_PLANE_INSTANCES"); } } En esta variable de código "SUPPORT_MANAGER_PLANE_INSTANCES" utilizada por @Value y el método processConfigureChange , si es necesario modificar el valor de esta variable, necesito modificar todas las referencias de esta variable, por lo que quiero definir una variable constante CONFIGURE_KEY @Value y el método processConfigureChange usa esta variable.
Gracias por la ayuda de @hirarqi
@Component public class InstanceConfig { private static final String CONFIGURE_KEY = "SUPPORT_MANAGER_PLANE_INSTANCES"; @Value("${" + CONFIGURE_KEY + "}") private String supportManageInstances; @ApolloConfigChangeListener(value = ConfigConsts.NAMESPACE_APPLICATION) public void processConfigureChange(ConfigChangeEvent event) { log.info("configure changed do somthing"); ConfigChange configChange = event.getChange(CONFIGURE_KEY); } }