Spring
June 6, 2020

M01 Q25 Can you use @Bean together with @Profile?

Yes, @Bean annotation can be used together with @Profile inside class annotated with @Configuration annotation on top of the method that returns an instance of the bean.

If a method annotated with @Bean does not have @Profile, that means that this bean will exist in all profiles.

You can specify one, multiple profiles or profile in which bean should not exists: