@Override
public void beanCreationMethod(BeanDefinitionRegistration beanDefinitionRegistration, ConfigurationProcessor cp,
String configurerBeanName, Class<?> configurerClass, Method m, Bean beanAnnotation) {
ScopedProxy proxyAnnotation = m.getAnnotation(ScopedProxy.class);
if (proxyAnnotation != null) {
// do some validation first related to scoping
String scope = beanAnnotation.scope();
if (DefaultScopes.PROTOTYPE.equals(scope) || DefaultScopes.SINGLETON.equals(scope))
throw new BeanDefinitionStoreException(String.format(
"[%s] contains an invalid annotation declaration: @ScopedProxy "
+ "cannot be used on a singleton/prototype bean", m));
cp.beanDefsGenerated++;
// TODO: could the code duplication be removed?
// copied from ScopedProxyBeanDefinitionDecorator
String originalBeanName = beanDefinitionRegistration.name;
RootBeanDefinition targetDefinition = beanDefinitionRegistration.rbd;
// Create a scoped proxy definition for the original bean name,
// "hiding" the target bean in an internal target definition.
String targetBeanName = ScopedProxyMethodProcessor.resolveHiddenScopedProxyBeanName(originalBeanName);
RootBeanDefinition scopedProxyDefinition = new RootBeanDefinition(ScopedProxyFactoryBean.class);
scopedProxyDefinition.getPropertyValues().addPropertyValue("targetBeanName", targetBeanName);
if (proxyAnnotation.proxyTargetClass()) {
targetDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
// ScopedFactoryBean's "proxyTargetClass" default is TRUE, so we
// don't need to set it explicitly here.
}
else {