Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
Spring @ConfigurationProperties herencia/anidamiento

¿Cómo cargo la configuración para crear una lista de Shape s que hereda los valores predeterminados y también admite la anulación?

Así es como se ven mis archivos application.yml...

 store: default: color: red size: 10 shapes: - id: square size: 20 - id: circle size: 30 color: black - id: rectangle

Y esto es lo que quiero...

 { "catalog": { "shapes": [ { "color": "red", // default "size": 20, // override "id": "square" }, { "color": "black", // override "size": 30, // override "id": "circle" }, { "color": "red", // default "size": 10, // default "id": "rectangle" } ] } }

Hasta ahora he intentado seguir pero faltan valores predeterminados en la herencia. En otras palabras, los valores predeterminados nunca se convierten en el objeto Shape .

 @lombok.Data @Component @ConfigurationProperties(prefix = "store") public class Catalog { private List<Shape> shapes; } @lombok.Data public class Shape extends DefaultConfig { private String id; } @lombok.Data @ConfigurationProperties(prefix = "store.default") @Component public class DefaultConfig { private String color; private int size; }
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No hay una manera mágica de hacer eso. El tamaño debe ser un número Integer y debe realizar un procesamiento posterior de su configuración para aplicar los valores predeterminados si es necesario.

Algo tan fácil como

 public class Catalog { private final DefaultConfig defaultConfig; public Catalog(DefaultConfig defaultConfig) { ... } @PostConstruct public void initialize() { // iterate over all the shapes and if the color or size is null // apply the default value from defalutConfig } }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!