[Spring] Spring bean의 scope를 prototype만 가능하도록 하려면?

250x250
반응형

public class MyBean implements BeanNameAware, BeanFactoryAware {

/**

* 빈 이름

*/

protected String beanName;


@Override

public void setBeanName(String name) {

this.beanName = name;

}


@Override

public void setBeanFactory(BeanFactory beanFactory) throws BeansException {

// scope가 prototype만 허용

if (beanFactory.isPrototype(this.beanName) == false) {

throw new BeanCreationException(this.beanName, "Scope of bean must be prototype");

}

}

}


반응형

Designed by JB FACTORY