How to exclude multiple Spring profiles in Kotlin?


I used this construction:


Okay, but I need to set do not use this bean with multiple profiles. Insofar as value field is String[], I wrote this:

@Profile(value  ["!local", "!test"])

and get this exception:

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type ‘ru.example.service.AuthenticationService’ available: expected single matching bean but found 2: testAuthenticationService,springAuthenticationService

As we see, the construction above not works. How to set profile in my case?


@Profile(value ["!local", "!test"]) is the equivalent of `@Profile(“!local | !test”) meaning that only beans that are BOTH local and test are excluded.

What you need is `@Profile(“!local & !test”) to exclude either local or test.

This is an example of De Morgan’s Law where !(foo | bar) !foo & !bar, but you had !foo | !bar !(foo & bar).

Answered By – Novaterata

Leave a Comment