Issue
I know that in java, multiple active profiles can be kept using -
@ActiveProfiles({"profile1", "profile2"})
But I need a similar construct for kotlin. Above doesnt work with kotlin and gives error saying - Unexpected tokens (use ';' to separate expressions on the same line)
. I also tried @ActiveProfiles(profile = arrayOf("profile1", "profile2"))
and also tried @Profile("profile1 & profile2")
. Nothing seems to work. Please help.
Solution
If you check the source of @ActiveProfiles
you'll see the following constructor:
/**
* Alias for {@link #profiles}.
* <p>This attribute may <strong>not</strong> be used in conjunction with
* {@link #profiles}, but it may be used <em>instead</em> of {@link #profiles}.
*/
@AliasFor("profiles")
String[] value() default {};
This means its expecting an array of strings for 'profiles' -> just create an array as you normally do it in Kotlin and pass it to the constructor like that:
@ActiveProfiles(profiles = arrayOf("profile1", "profile1"))
Answered By - Katharina
Answer Checked By - Candace Johnson (JavaFixing Volunteer)