I have a BeanPostProcessor bean and I want to inject two string variables with values from application.properties file. However, they are not getting injected and left with a placeholder's value.
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
@Value("${property1}")
private String property1;
@Value("${property2}")
private String property2;
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
...
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
...
return bean;
}
}
In both method values of the variables are ${property1}
and ${property2}
.
I've tried injecting them in a regular bean and it works fine, so it definitely has to do something with the bean being BeanPostProcessor.
Is there a way to inject values somehow? I'm using Spring Boot 2.2.0.