2

Quiero obtener los datos en el java de un array de clave/valor que estará en el YML

Yml:

profiles: 
 - type: user
   url:  www
 - type: admin
   url:  http

Lo recojo como:

@Value("${profiles}")
private List<Profile> profiles;

Y la clase asociada es:

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Profile {
    private String type;
    private String url;
}

Pero me da error al intentar arrancar:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'api': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'profiles' in value "${profiles}"

¿ Qué falla ? Gracias.

1 respuesta 1

2

Ya lo resolví: Para recogerlos:

   @Autowired
   ListRoles profiles;

La clase Principal y la subClase:

@ConfigurationProperties(prefix = "available-channels-list")
@Configuration
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ListRoles {
  List<Profile> profiles;
}


@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Profile {
    private String type;
    private String url;
}

Faltaba la etiqueta

@ConfigurationProperties(prefix = "available-channels-list")
@Configuration

En el yml

available-channels-list:
 profiles: 
  -
    type: "user"
    url:  "www"
  -
    type: "admin"
    url:  "http"

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.