@Bean @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) public ProxyFactoryBean myObject() { ProxyFactoryBean pfb = new ProxyFactoryBean(); pfb.setTargetSource(poolTargetSource()); return pfb; }
@SuppressWarnings("unchecked") private <T> T lazyBean(Class<T> interfaceName) { LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource(); String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( applicationContext, interfaceName); if (beanNamesForType.length == 0) { return null; } String beanName; if (beanNamesForType.length > 1) { List<String> primaryBeanNames = Arrays.stream(beanNamesForType) .filter(i -> applicationContext instanceof ConfigurableApplicationContext) .filter(n -> ((ConfigurableApplicationContext) applicationContext).getBeanFactory().getBeanDefinition(n).isPrimary()) .collect(Collectors.toList()); Assert.isTrue(primaryBeanNames.size() != 0, () -> "Found " + beanNamesForType.length + " beans for type " + interfaceName + ", but none marked as primary"); Assert.isTrue(primaryBeanNames.size() == 1, () -> "Found " + primaryBeanNames.size() + " beans for type " + interfaceName + " marked as primary"); beanName = primaryBeanNames.get(0); } else { beanName = beanNamesForType[0]; } lazyTargetSource.setTargetBeanName(beanName); lazyTargetSource.setBeanFactory(applicationContext); ProxyFactoryBean proxyFactory = new ProxyFactoryBean(); proxyFactory = objectPostProcessor.postProcess(proxyFactory); proxyFactory.setTargetSource(lazyTargetSource); return (T) proxyFactory.getObject(); }
@SuppressWarnings("unchecked") private <T> T lazyBean(Class<T> interfaceName) { LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource(); String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( applicationContext, interfaceName); if (beanNamesForType.length == 0) { return null; } Assert.isTrue(beanNamesForType.length == 1, () -> "Expecting to only find a single bean for type " + interfaceName + ", but found " + Arrays.asList(beanNamesForType)); lazyTargetSource.setTargetBeanName(beanNamesForType[0]); lazyTargetSource.setBeanFactory(applicationContext); ProxyFactoryBean proxyFactory = new ProxyFactoryBean(); proxyFactory = objectPostProcessor.postProcess(proxyFactory); proxyFactory.setTargetSource(lazyTargetSource); return (T) proxyFactory.getObject(); }
@SuppressWarnings("unchecked") private <T> T lazyBean(Class<T> interfaceName) { LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource(); String[] beanNamesForType = context.getBeanNamesForType(interfaceName); Assert.isTrue(beanNamesForType.length == 1 , "Expecting to only find a single bean for type " + interfaceName + ", but found " + Arrays.asList(beanNamesForType)); lazyTargetSource.setTargetBeanName(beanNamesForType[0]); lazyTargetSource.setBeanFactory(context); ProxyFactoryBean proxyFactory = new ProxyFactoryBean(); proxyFactory.setTargetSource(lazyTargetSource); proxyFactory.setInterfaces(new Class[] { interfaceName }); return (T) proxyFactory.getObject(); }
private AclPredicateTargetSource installAclPredicateTargetSource() { synchronized (cachedCriteriaQuery) { Predicate restriction = cachedCriteriaQuery.getRestriction(); if (restriction instanceof Advised) { Advised advised = (Advised) restriction; if (advised.getTargetSource() instanceof AclPredicateTargetSource) { return (AclPredicateTargetSource) advised.getTargetSource(); } } AclPredicateTargetSource targetSource = new AclPredicateTargetSource(em.getCriteriaBuilder(), restriction); ProxyFactoryBean factoryBean = new ProxyFactoryBean(); factoryBean.setTargetSource(targetSource); factoryBean.setAutodetectInterfaces(true); Predicate enhancedPredicate = (Predicate) factoryBean.getObject(); logger.debug("ACL Jpa Specification target source initialized for criteria {}", cachedCriteriaQuery); // install proxy inside criteria cachedCriteriaQuery.where(enhancedPredicate); return targetSource; } }
@SuppressWarnings("unchecked") private <T> T lazyBean(Class<T> interfaceName) { LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource(); String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( applicationContext, interfaceName); if (beanNamesForType.length == 0) { return null; } Assert.isTrue(beanNamesForType.length == 1, () -> "Expecting to only find a single bean for type " + interfaceName + ", but found " + Arrays.asList(beanNamesForType)); lazyTargetSource.setTargetBeanName(beanNamesForType[0]); lazyTargetSource.setBeanFactory(applicationContext); ProxyFactoryBean proxyFactory = new ProxyFactoryBean(); proxyFactory = objectPostProcessor.postProcess(proxyFactory); proxyFactory.setTargetSource(lazyTargetSource); return (T) proxyFactory.getObject(); }
public ProxyFactoryBean createProxyFactoryBean() { ProxyFactoryBean pfb = new ProxyFactoryBean(); pfb.setTargetSource(setupObjectPool());
private void createProxy() { Class beanclass = getTargetClass(); if (pea) { RSACPeaProxyFactory ppf = new RSACPeaProxyFactory(beanclass, this); proxy = ppf.getProxy(); } else { ProxyFactoryBean pfb = new ProxyFactoryBean(); if (beanclass.isInterface()) { pfb.setInterfaces(new Class[] { beanclass }); } else { pfb.setProxyTargetClass(true); } pfb.setTargetSource(this); pfb.setBeanFactory(beanFactory); proxy = pfb.getObject(); } }
pfb.setProxyTargetClass(true); pfb.setTargetSource(rlts); pfb.setBeanFactory(blfactory);