Created
August 4, 2023 00:43
-
-
Save sandipchitale/d5c1699c5aef9e05ea0c6a7959b6effe to your computer and use it in GitHub Desktop.
ConfigurationPropertiesBindingPostProcessor #springboot #configprop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public static class CPPP extends ConfigurationPropertiesBindingPostProcessor { | |
private ApplicationContext applicationContext; | |
@Override | |
public void setApplicationContext(ApplicationContext applicationContext) { | |
super.setApplicationContext(applicationContext); | |
this.applicationContext = applicationContext; | |
} | |
@Override | |
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | |
// Only if this is ConfigurationProperties bean | |
if (ConfigurationPropertiesBean.get(applicationContext, bean, beanName) != null) { | |
if (bean instanceof ServerProperties serverProperties) { | |
return bean; | |
} | |
} | |
return super.postProcessAfterInitialization(bean, beanName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment