We are using this and would like to know what it actually does, looked on the web for detailed explanation but didn;t find anything for exclamation,profile,spring
what does this @Profile("!json") mean
1.2k Views Asked by Julie At
2
There are 2 best solutions below
0

Example in Spring boot
@Bean
@Profile("!prod")
public CommandLineRunner dataLoader(IngredientRepository repo,
UserRepository userRepo, PasswordEncoder encoder) {
...
}
Here, the exclamation mark (!) negates the profile name. Effectively, it states that the CommandLineRunner bean will be created if the prod profile isn’t active.
The feature "@Profile" in Spring is actually a feature in "Spring-boots". Read the Spring boot docs for more information on how to configure and use it.
In your example, it simply means that the component or component annotated with
@Profile(“!json”)
is not available if the active profile (set with the propertyspring.profiles.active
) is 'json'.