Posts

Showing posts from November, 2019

Java Optional - How to use correctly

How to use Java Optional correctly, what to avoid and good practices: https://dzone.com/articles/using-optional-correctly-is-not-optional

Spring boot - Conditional Bean Creation

@ConditionalOnBean(name = "otherNeededBean") The bean is only created, if the bean "otherNeededBean" already exist. @ConditionalOnMissingBean The bean is only created, if no other bean with the same name already exist. @ConditionalOnMissingBean(type = "alternativeBean") The bean is only created, if bean "alternativeBean" doesn't exist. Conditional based on Environment property Add proprty file to the Configuration class. @PropertySource("classpath:myspecific.properties") public class MySpecificConfiguration {} @ConditionalOnProperty(name = "email.notification", havingValue = "true") @Bean public MailService ... myspecific.properties: email.notification = true | false