@SuppressWarnings("unchecked") @Override public void afterPropertiesSet() { if (!applicationContext.isPrototype(prototypeBeanName)) { throw new IncompatibleAggregateException( format("Cannot initialize repository '%s'. " + "The bean with name '%s' does not have the 'prototype' scope.", beanName, prototypeBeanName)); } this.delegate = new AbstractAggregateFactory<T>(getAggregateType()) { @Override protected T doCreateAggregate(String aggregateIdentifier, DomainEventMessage firstEvent) { return (T) applicationContext.getBean(prototypeBeanName); } @Override protected T postProcessInstance(T aggregate) { applicationContext.getAutowireCapableBeanFactory().configureBean(aggregate, prototypeBeanName); return aggregate; } }; } }
@Test public void testPrototype() { ApplicationContext context = createContext(ScopedProxyMode.NO); ScopedTestBean bean = (ScopedTestBean) context.getBean("prototype"); assertNotNull(bean); assertTrue(context.isPrototype("prototype")); assertFalse(context.isSingleton("prototype")); }
public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); }
@Test public void testSingletonScopeWithNoProxy() { RequestContextHolder.setRequestAttributes(oldRequestAttributes); ApplicationContext context = createContext(ScopedProxyMode.NO); ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton"); assertTrue(context.isSingleton("singleton")); assertFalse(context.isPrototype("singleton")); // should not be a proxy assertFalse(AopUtils.isAopProxy(bean)); assertEquals(DEFAULT_NAME, bean.getName()); bean.setName(MODIFIED_NAME); RequestContextHolder.setRequestAttributes(newRequestAttributes); // not a proxy so this should not have changed assertEquals(MODIFIED_NAME, bean.getName()); // singleton bean, so name should be modified even after lookup ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton"); assertEquals(MODIFIED_NAME, bean2.getName()); }
/** * Delegates to internal ApplicationContext supplied by constructor */ public final boolean isPrototype(String arg0) throws NoSuchBeanDefinitionException { return context.isPrototype(arg0); }
public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); } public Object getBean(String name) throws BeansException {
@Override public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); }
public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return wrappedApplicationContext.isPrototype(name); }
public boolean has(String key) { return applicationContext.isPrototype(key); }
@Override public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return wrapped.isPrototype(name); }
public boolean has(String key) { return applicationContext.isPrototype(key); }
public boolean isPrototype(String arg0) throws NoSuchBeanDefinitionException { return target.isPrototype(arg0); }
public boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); }
public static boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); }
public static boolean isPrototype(String name) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype(name); }
public static boolean isPrototype(String name) { return context.isPrototype(name); }
static BeanScope findBeanScope(ApplicationContext context, String beanName) { if (context.isSingleton(beanName)) { return BeanScope.SINGLETON; } else if (context.isPrototype(beanName)) { return BeanScope.PROTOTYPE; } else { //TODO log warning and proceed throw new RuntimeException("Unsupported bean scope"); } } }
@Override public boolean isPrototype( String s ) throws NoSuchBeanDefinitionException { return applicationContext.isPrototype( s ); }
static BeanScope findBeanScope(ApplicationContext context, String beanName) { if (context.isSingleton(beanName)) { return BeanScope.SINGLETON; } else if (context.isPrototype(beanName)) { return BeanScope.PROTOTYPE; } else { //TODO log warning and proceed throw new RuntimeException("Unsupported bean scope"); } } }
protected boolean isSessionScopedUI(VaadinRequest request) { return !SpringApplicationContext.getApplicationContext().isPrototype(getUIBeanName(request)); }