Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aliasing a bean outside the bean definition using Java config in Spring Boot

Tags:

How to alias a bean outside the bean definition using Java config in Spring Boot?

like image 296
Prajwel Avatar asked Mar 01 '19 04:03

Prajwel


1 Answers

I have this as well, and solved it like this:

@Component
public class AliasConfiguration implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        beanFactory.registerAlias("originalBeanName", "newAlias");
        beanFactory.registerAlias("originalBeanName", "newAlias2");
        beanFactory.registerAlias("otherOriginalBeanName", "newAlias3");
    }
}
like image 54
Scott Carlson Avatar answered Oct 16 '22 18:10

Scott Carlson