what does this @Profile("!json") mean

1.2k Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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 property spring.profiles.active) is 'json'.

0
On

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.