String className = mbd.getBeanClassName(); if (className != null) { Object evaluated = evaluateBeanDefinitionString(className, mbd);
@Test public void beanClassName() { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName()); RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition(); assertFalse(rbd.hasBeanClass()); assertEquals(TestBean.class.getName(), rbd.getBeanClassName()); }
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) { mbdToUse = new RootBeanDefinition(mbd); mbdToUse.setBeanClass(resolvedClass);
@Test public void beanClassNameWithFactoryMethod() { BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName(), "create"); RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition(); assertFalse(rbd.hasBeanClass()); assertEquals(TestBean.class.getName(), rbd.getBeanClassName()); assertEquals("create", rbd.getFactoryMethodName()); }
String className = mbd.getBeanClassName(); if (className != null) { Object evaluated = evaluateBeanDefinitionString(className, mbd);
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
this.beanDefinition.getResourceDescription(), this.beanName, "Cannot create inner bean '" + innerBeanName + "' " + (mbd != null && mbd.getBeanClassName() != null ? "of type [" + mbd.getBeanClassName() + "] " : "") + "while setting " + argName, ex);
if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) { mbdToUse = new RootBeanDefinition(mbd); mbdToUse.setBeanClass(resolvedClass);
this.beanDefinition.getResourceDescription(), this.beanName, "Cannot create inner bean '" + innerBeanName + "' " + (mbd != null && mbd.getBeanClassName() != null ? "of type [" + mbd.getBeanClassName() + "] " : "") + "while setting " + argName, ex);
private Class<?> doResolveBeanClass(RootBeanDefinition mbd, Class<?>... typesToMatch) throws ClassNotFoundException { if (!ObjectUtils.isEmpty(typesToMatch)) { ClassLoader tempClassLoader = getTempClassLoader(); if (tempClassLoader != null) { if (tempClassLoader instanceof DecoratingClassLoader) { DecoratingClassLoader dcl = (DecoratingClassLoader) tempClassLoader; for (Class<?> typeToMatch : typesToMatch) { dcl.excludeClass(typeToMatch.getName()); } } String className = mbd.getBeanClassName(); return (className != null ? ClassUtils.forName(className, tempClassLoader) : null); } } return mbd.resolveBeanClass(getBeanClassLoader()); }
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
this.beanDefinition.getResourceDescription(), this.beanName, "Cannot create inner bean '" + innerBeanName + "' " + (mbd != null && mbd.getBeanClassName() != null ? "of type [" + mbd.getBeanClassName() + "] " : "") + "while setting " + argName, ex);
protected Class resolveBeanClass(RootBeanDefinition mbd, String beanName, Class[] typesToMatch) { try { if (typesToMatch != null) { ClassLoader tempClassLoader = getTempClassLoader(); if (tempClassLoader != null) { if (tempClassLoader instanceof DecoratingClassLoader) { DecoratingClassLoader dcl = (DecoratingClassLoader) tempClassLoader; for (int i = 0; i < typesToMatch.length; i++) { dcl.excludeClass(typesToMatch[i].getName()); } } String className = mbd.getBeanClassName(); return (className != null ? ClassUtils.forName(className, tempClassLoader) : null); } } return mbd.resolveBeanClass(getBeanClassLoader()); } catch (ClassNotFoundException ex) { throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); } catch (LinkageError err) { throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err); } } }
/** * Create the {@link RuntimeBeanReference} used to apply the caching interceptor * * @return Reference to the {@link RuntimeBeanReference}. Should never be null. */ protected RuntimeBeanReference setupPointcut(ParserContext parserContext, Object elementSource, RuntimeBeanReference cacheOperationSourceRuntimeReference, RuntimeBeanReference cacheInterceptorSourceRuntimeReference) { final RootBeanDefinition pointcut = new RootBeanDefinition(CacheStaticMethodMatcherPointcut.class); pointcut.setSource(elementSource); pointcut.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addIndexedArgumentValue(0, cacheOperationSourceRuntimeReference); constructorArgumentValues.addIndexedArgumentValue(1, cacheInterceptorSourceRuntimeReference); pointcut.setConstructorArgumentValues(constructorArgumentValues); final String pointcutBeanName = pointcut.getBeanClassName() + "_" + cacheInterceptorSourceRuntimeReference.getBeanName(); final BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(pointcutBeanName, pointcut); return new RuntimeBeanReference(pointcutBeanName); }
throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), ex); throw new CannotLoadBeanClassException(mbd.getResourceDescription(), beanName, mbd.getBeanClassName(), err);
/** * Looks for prototype beans who's class extends ConfigurableBean. */ public void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; for (String name : beanFactory.getBeanDefinitionNames()) { BeanDefinition bd = beanFactory.getMergedBeanDefinition(name); if (bd instanceof RootBeanDefinition) { RootBeanDefinition rbd = (RootBeanDefinition) bd; if (rbd.isPrototype()) { try { Class<?> beanClass = rbd.resolveBeanClass(beanFactory.getBeanClassLoader()); if (beanClass != null && ConfigurableBean.class.isAssignableFrom(beanClass)) { prototypes.put(beanClass, name); } } catch (ClassNotFoundException ex) { throw new CannotLoadBeanClassException( null, name, rbd.getBeanClassName(), ex); } } } } if (!prototypes.isEmpty()) { ConfigurableBean.configurer = this; } }
private static String generateName(ConfigurableListableBeanFactory registry, RootBeanDefinition definition) { String generatedBeanName = definition.getBeanClassName(); if (generatedBeanName == null) { if (definition.getParentName() != null) { generatedBeanName = definition.getParentName() + "$child"; } else if (definition.getFactoryBeanName() != null) { generatedBeanName = definition.getFactoryBeanName() + "$created"; } } if (!StringUtils.hasText(generatedBeanName)) { throw new BeanDefinitionStoreException( "Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't " + "generate bean name"); } String id = generatedBeanName; // Top-level bean: use plain class name. // Increase counter until the id is unique. int counter = -1; while (counter == -1 || (registry.containsSingleton(id))) { counter++; id = generatedBeanName + "#" + counter; } return id; } }
private static String generateName(ConfigurableListableBeanFactory registry, RootBeanDefinition definition) { String generatedBeanName = definition.getBeanClassName(); if (generatedBeanName == null) { if (definition.getParentName() != null) { generatedBeanName = definition.getParentName() + "$child"; } else if (definition.getFactoryBeanName() != null) { generatedBeanName = definition.getFactoryBeanName() + "$created"; } } if (!StringUtils.hasText(generatedBeanName)) { throw new BeanDefinitionStoreException( "Unnamed bean definition specifies neither " + "'class' nor 'parent' nor 'factory-bean' - can't generate bean name"); } String id = generatedBeanName; // Top-level bean: use plain class name. // Increase counter until the id is unique. int counter = -1; while (counter == -1 || (registry.containsSingleton(id))) { counter++; id = generatedBeanName + "#" + counter; } return id; } }
private static String generateName(ConfigurableListableBeanFactory registry, RootBeanDefinition definition) { String generatedBeanName = definition.getBeanClassName(); if (generatedBeanName == null) { if (definition.getParentName() != null) { generatedBeanName = definition.getParentName() + "$child"; } else if (definition.getFactoryBeanName() != null) { generatedBeanName = definition.getFactoryBeanName() + "$created"; } } if (!StringUtils.hasText(generatedBeanName)) { throw new BeanDefinitionStoreException( "Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't " + "generate bean name"); } String id = generatedBeanName; // Top-level bean: use plain class name. // Increase counter until the id is unique. int counter = -1; while (counter == -1 || (registry.containsSingleton(id))) { counter++; id = generatedBeanName + "#" + counter; } return id; } }