protected void visitScope(BeanDefinition beanDefinition) { String scope = beanDefinition.getScope(); if (scope != null) { String resolvedScope = resolveStringValue(scope); if (!scope.equals(resolvedScope)) { beanDefinition.setScope(resolvedScope); } } }
private boolean scanScopedBean(ScanScopedBeans scanScopedBeans, Set<String> scopes, BeanDefinition beanDefinition) { return scanScopedBeans != null && (scopes.size() == 0 || scopes.contains(beanDefinition.getScope())); }
/** * Evaluate the given String as contained in a bean definition, * potentially resolving it as an expression. * @param value the value to check * @param beanDefinition the bean definition that the value comes from * @return the resolved value * @see #setBeanExpressionResolver */ @Nullable protected Object evaluateBeanDefinitionString(@Nullable String value, @Nullable BeanDefinition beanDefinition) { if (this.beanExpressionResolver == null) { return value; } Scope scope = null; if (beanDefinition != null) { String scopeName = beanDefinition.getScope(); if (scopeName != null) { scope = getRegisteredScope(scopeName); } } return this.beanExpressionResolver.evaluate(value, new BeanExpressionContext(this, scope)); }
protected void visitScope(BeanDefinition beanDefinition) { String scope = beanDefinition.getScope(); if (scope != null) { String resolvedScope = resolveStringValue(scope); if (!scope.equals(resolvedScope)) { beanDefinition.setScope(resolvedScope); } } }
appendArray(result, bf.getAliases(beanName)); result.append(",\n"); String scope = bd.getScope(); if (!StringUtils.hasText(scope)) { scope = BeanDefinition.SCOPE_SINGLETON;
/** * Evaluate the given String as contained in a bean definition, * potentially resolving it as an expression. * @param value the value to check * @param beanDefinition the bean definition that the value comes from * @return the resolved value * @see #setBeanExpressionResolver */ @Nullable protected Object evaluateBeanDefinitionString(@Nullable String value, @Nullable BeanDefinition beanDefinition) { if (this.beanExpressionResolver == null) { return value; } Scope scope = null; if (beanDefinition != null) { String scopeName = beanDefinition.getScope(); if (scopeName != null) { scope = getRegisteredScope(scopeName); } } return this.beanExpressionResolver.evaluate(value, new BeanExpressionContext(this, scope)); }
bd.setScope(containingBean.getScope());
private Object evaluateBeanDefinitionString(ConfigurableBeanFactory beanFactory, String value, BeanDefinition beanDefinition) { if (beanFactory.getBeanExpressionResolver() == null) { return value; } Scope scope = (beanDefinition != null ? beanFactory .getRegisteredScope(beanDefinition.getScope()) : null); return beanFactory.getBeanExpressionResolver() .evaluate(value, new BeanExpressionContext(beanFactory, scope)); }
private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) { GenericWebApplicationContext context = new GenericWebApplicationContext(); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); scanner.setIncludeAnnotationConfig(false); scanner.setBeanNameGenerator((definition, registry) -> definition.getScope()); scanner.setScopedProxyMode(scopedProxyMode); // Scan twice in order to find errors in the bean definition compatibility check. scanner.scan(getClass().getPackage().getName()); scanner.scan(getClass().getPackage().getName()); context.refresh(); return context; }
@Test public void testCustomScopeMetadataResolver() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/context/annotation/customScopeResolverTests.xml"); BeanDefinition bd = context.getBeanFactory().getBeanDefinition("fooServiceImpl"); assertEquals("myCustomScope", bd.getScope()); assertFalse(bd.isSingleton()); }
mbd.setScope(containingBd.getScope());
public BeanDefinitionBuilder createBeanDefinitionBuilder(Element element, ParserContext parserContext, Class<?> cls) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); builder.getRawBeanDefinition().setBeanClass(cls); builder.getRawBeanDefinition() .setSource(parserContext.extractSource(element)); if (parserContext.isNested()) { builder.setScope(parserContext.getContainingBeanDefinition() .getScope()); } if (parserContext.isDefaultLazyInit()) { builder.setLazyInit(true); } return builder; }
public BeanDefinitionBuilder createBeanDefinitionBuilder(Element element, ParserContext parserContext, Class<?> cls) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(); builder.getRawBeanDefinition().setBeanClass(cls); builder.getRawBeanDefinition() .setSource(parserContext.extractSource(element)); if (parserContext.isNested()) { builder.setScope(parserContext.getContainingBeanDefinition() .getScope()); } if (parserContext.isDefaultLazyInit()) { builder.setLazyInit(true); } return builder; }
@Test public void testScopeInheritanceForChildBeanDefinitions() { RootBeanDefinition parent = new RootBeanDefinition(); parent.setScope("bonanza!"); AbstractBeanDefinition child = new ChildBeanDefinition("parent"); child.setBeanClass(TestBean.class); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); factory.registerBeanDefinition("parent", parent); factory.registerBeanDefinition("child", child); BeanDefinition def = factory.getMergedBeanDefinition("child"); assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope()); }
if (containingBd != null) { builder.setScope(containingBd.getScope());
proxyDefinition.setScope(targetDefinition.getScope()); proxyDefinition.setLazyInit(targetDefinition.isLazyInit());
@Test public void testStepListenerStepScoped() { @SuppressWarnings("resource") GenericApplicationContext applicationContext = new GenericApplicationContext(); AbstractBeanDefinition newBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition("stepListener").getBeanDefinition(); newBeanDefinition.setScope("step"); applicationContext.registerBeanDefinition("stepListener", newBeanDefinition); ListenerParser listenerParser = new ListenerParser(StepListenerFactoryBean.class, "listeners"); listenerParser.applyListenerScope("stepListener", applicationContext); BeanDefinition beanDefinition = applicationContext.getBeanDefinition("stepListener"); assertEquals("step", beanDefinition.getScope()); }
@Test public void testJobListenerSingletonScoped() { @SuppressWarnings("resource") GenericApplicationContext applicationContext = new GenericApplicationContext(); AbstractBeanDefinition newBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition("jobListener").getBeanDefinition(); newBeanDefinition.setScope("step"); applicationContext.registerBeanDefinition("jobListener", newBeanDefinition); ListenerParser listenerParser = new ListenerParser(JsrJobListenerFactoryBean.class, "jobExecutionListeners"); listenerParser.applyListenerScope("jobListener", applicationContext); BeanDefinition beanDefinition = applicationContext.getBeanDefinition("jobListener"); assertEquals("job", beanDefinition.getScope()); } }
setParentName(original.getParentName()); setBeanClassName(original.getBeanClassName()); setScope(original.getScope()); setAbstract(original.isAbstract()); setLazyInit(original.isLazyInit());