Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

654
Vistas
How to create Java array in Kotlin for @PropertySource?

I am trying to configure @PropertySource for my Spring-based application.

In Java, I could do something like this:

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

I tried arrayOf in Kotlin but I end up with a type mismatch:

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

What is the right way to go here?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The value annotation parameter is handled in a special way in Kotlin (following its special handling in Java), and if it has an array type, Kotlin converts it to a vararg. Therefore, the correct syntax here is simply:

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

If you do want to specify the parameter name explicitly, use the spread operator to expand the array into varargs:

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

For any other array annotation parameter, you should simply use arrayOf() normally.

about 4 years ago · Santiago Trujillo Denunciar

0

Adding this in case it helps anyone...

I needed multiple instances of the same annotation, but I also needed to set other attributes of the annotation.

@Configuration
@PropertySources(
        PropertySource(
                value = ["classpath:consul.properties"]),
        PropertySource(
                value = ["file:/run/example/consul.properties"],
                ignoreResourceNotFound = true)
)
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda