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

653
Views
¿Cómo crear una matriz Java en Kotlin para @PropertySource?

Estoy tratando de configurar @PropertySource para mi aplicación basada en Spring.

En Java, podría hacer algo como esto:

 @PropertySource(value = {"application.properties","other.properties" })

arrayOf en Kotlin pero termino con una falta de coincidencia de tipo:

 @PropertySource(value = arrayOf("application.properties", "other.properties"))

¿Cuál es el camino correcto para ir aquí?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

El parámetro de anotación de value se maneja de una manera especial en Kotlin (siguiendo su manejo especial en Java), y si tiene un tipo de matriz, Kotlin lo convierte en un vararg . Por lo tanto, la sintaxis correcta aquí es simplemente:

 @PropertySource("application.properties", "other.properties")

Si desea especificar el nombre del parámetro explícitamente, use el operador de expansión para expandir la matriz en varargs:

 @PropertySource(value = *arrayOf("application.properties", "other.properties"))

Para cualquier otro parámetro de anotación de matriz, simplemente debe usar arrayOf() normalmente.

about 4 years ago · Santiago Trujillo Report

0

Agrego esto en caso de que ayude a alguien...

Necesitaba varias instancias de la misma anotación, pero también necesitaba establecer otros atributos de la anotación.

 @Configuration @PropertySources( PropertySource( value = ["classpath:consul.properties"]), PropertySource( value = ["file:/run/example/consul.properties"], ignoreResourceNotFound = true) )
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!