Can I negate (!) a collection of spring profiles?

Since Spring 5.1 (incorporated in Spring Boot 2.1) it is possible to use a profile expression inside profile string annotation (see the description in Profile.of(..) for details).

So to exclude your bean from certain profiles you can use an expression like this:

@Profile("!dev & !prof1 & !prof2")

Other logical operators can be used as well, for example:

@Profile("test | local")

Leave a Comment