private void setListableBeanFactory() { ListableBeanFactory beanFactory = new StaticWebApplicationContext() { @Override public String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) { if (type.isAssignableFrom( ResourceServerTokenServicesConfiguration.class)) { return new String[] { "ResourceServerTokenServicesConfiguration" }; } return new String[0]; } }; this.properties.setBeanFactory(beanFactory); }
/** * @throws SQLException If Setup of emulation database failed, or if the * application JDBC work fails. */ static public void main(String[] sa) throws SQLException { if (sa.length != 1) throw new IllegalArgumentException(SYNTAX_MSG); String authSpringFile = null; if (sa[0].equals("LDAP")) { authSpringFile = "ldapbeans.xml"; } else if (sa[0].equals("JAAS")) { authSpringFile = "jaasbeans.xml"; } else if (sa[0].equals("HsqldbSlave")) { authSpringFile = "slavebeans.xml"; } else if (sa[0].equals("JAAS_LDAP")) { authSpringFile = "jaasldapbeans.xml"; } if (authSpringFile == null) throw new IllegalArgumentException(SYNTAX_MSG); SpringExtAuth.prepMemoryDatabases(!sa[0].equals("HsqldbSlave")); ApplicationContext ctx = new ClassPathXmlApplicationContext("beandefs.xml", authSpringFile); ListableBeanFactory bf = (ListableBeanFactory) ctx; JdbcAppClass appBean = bf.getBean("appBean", JdbcAppClass.class); appBean.doJdbcWork(); }
public void testAppContextClassHierarchy() { Class<?>[] clazz = ClassUtils.getClassHierarchy(OsgiBundleXmlApplicationContext.class, ClassUtils.ClassSet.ALL_CLASSES); //Closeable.class, Class<?>[] expected = new Class<?>[] { OsgiBundleXmlApplicationContext.class, AbstractDelegatedExecutionApplicationContext.class, AbstractOsgiBundleApplicationContext.class, AbstractRefreshableApplicationContext.class, AbstractApplicationContext.class, DefaultResourceLoader.class, ResourceLoader.class, AutoCloseable.class, DelegatedExecutionOsgiBundleApplicationContext.class, ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class, ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class, HierarchicalBeanFactory.class, ApplicationEventPublisher.class, ResourcePatternResolver.class, MessageSource.class, BeanFactory.class, DisposableBean.class }; assertTrue(compareArrays(expected, clazz)); }
protected Scheduler findScheduler(String schedulerName) throws SchedulerException { if (this.beanFactory instanceof ListableBeanFactory) { ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (String beanName : beanNames) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName); if (schedulerName.equals(schedulerBean.getSchedulerName())) { return schedulerBean; } } } Scheduler schedulerInRepo = SchedulerRepository.getInstance().lookup(schedulerName); if (schedulerInRepo == null) { throw new IllegalStateException("No Scheduler named '" + schedulerName + "' found"); } return schedulerInRepo; }
/** * Find an EntityManagerFactory with the given name in the given * Spring application context (represented as ListableBeanFactory). * <p>The specified unit name will be matched against the configured * persistence unit, provided that a discovered EntityManagerFactory * implements the {@link EntityManagerFactoryInfo} interface. If not, * the persistence unit name will be matched against the Spring bean name, * assuming that the EntityManagerFactory bean names follow that convention. * <p>If no unit name has been given, this method will search for a default * EntityManagerFactory through {@link ListableBeanFactory#getBean(Class)}. * @param beanFactory the ListableBeanFactory to search * @param unitName the name of the persistence unit (may be {@code null} or empty, * in which case a single bean of type EntityManagerFactory will be searched for) * @return the EntityManagerFactory * @throws NoSuchBeanDefinitionException if there is no such EntityManagerFactory in the context * @see EntityManagerFactoryInfo#getPersistenceUnitName() */ public static EntityManagerFactory findEntityManagerFactory( ListableBeanFactory beanFactory, String unitName) throws NoSuchBeanDefinitionException { Assert.notNull(beanFactory, "ListableBeanFactory must not be null"); if (StringUtils.hasLength(unitName)) { // See whether we can find an EntityManagerFactory with matching persistence unit name. String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, EntityManagerFactory.class); for (String candidateName : candidateNames) { EntityManagerFactory emf = (EntityManagerFactory) beanFactory.getBean(candidateName); if (emf instanceof EntityManagerFactoryInfo) { if (unitName.equals(((EntityManagerFactoryInfo) emf).getPersistenceUnitName())) { return emf; } } } // No matching persistence unit found - simply take the EntityManagerFactory // with the persistence unit name as bean name (by convention). return beanFactory.getBean(unitName, EntityManagerFactory.class); } else { // Find unique EntityManagerFactory bean in the context, falling back to parent contexts. return beanFactory.getBean(EntityManagerFactory.class); } }
/** * Get the {@link DataSource} type bean name which corresponds to given data context id * @param registry Bean registry * @param beanFactory Bean factory * @param dataContextId Optional data context id * @return The DataSource bean name, or <code>null</code> if not found */ private static String getDataSourceBeanName(BeanDefinitionRegistry registry, BeanFactory beanFactory, String dataContextId) { // check unique DataSource if no data context id specified if (dataContextId == null && beanFactory instanceof ListableBeanFactory) { String[] dataSourceBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( (ListableBeanFactory) beanFactory, DataSource.class, false, false); if (dataSourceBeanNames != null && dataSourceBeanNames.length == 1) { return dataSourceBeanNames[0]; } } // check bean name using data context id String dsBeanName = BeanRegistryUtils.buildBeanName(dataContextId, EnableDataSource.DEFAULT_DATASOURCE_BEAN_NAME); if (registry.containsBeanDefinition(dsBeanName) && beanFactory.isTypeMatch(dsBeanName, DataSource.class)) { return dsBeanName; } return null; }
/** * Checks if a bean of given type and bound to given data context id is already registered * @param beanFactory Bean factory * @param registry Bean registry * @param type Bean type to check * @param dataContextId Data context id * @param defaultBeanName Default bean name to check * @return The registered bean name if found, <code>null</code> otherwise */ private static String isBeanRegistered(ListableBeanFactory beanFactory, BeanDefinitionRegistry registry, Class<?> type, String dataContextId, String defaultBeanName) { String[] beanNames = beanFactory.getBeanNamesForType(type); if (beanNames != null && beanNames.length > 0) { for (String beanName : beanNames) { BeanDefinition bd = registry.getBeanDefinition(beanName); if (bd instanceof DataContextBoundBeanDefinition) { String did = ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null); if ((dataContextId == null && did == null) || (dataContextId != null && dataContextId.equals(did))) { return beanName; } } else { if (dataContextId == null) { return beanName; } } } } if (defaultBeanName != null && registry.containsBeanDefinition(defaultBeanName)) { return defaultBeanName; } return null; }
@Override public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) { // Register JPA Datastore (transactional) if (beanFactory instanceof ListableBeanFactory) { String[] emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( (ListableBeanFactory) beanFactory, EntityManagerFactory.class, true, false); if (emfBeanNames == null || emfBeanNames.length == 0) { emfBeanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors((ListableBeanFactory) beanFactory, AbstractEntityManagerFactoryBean.class, true, false); } if (emfBeanNames != null && emfBeanNames.length == 1) { String emfBeanName = (emfBeanNames[0].startsWith("&")) ? emfBeanNames[0].substring(1) : emfBeanNames[0]; JpaDatastoreRegistrar.registerDatastore(registry, null, PrimaryMode.AUTO, emfBeanName, true, false, beanClassLoader); } } }
public void addParameter(Object askFor, Object valueParam) throws InstantiationException, IllegalAccessException { try { Class clz = ClassUtils.forName((String)askFor); if (log.isDebugEnabled()) { log.debug("trying to resolve the following class from the Spring bean container: " + clz.getName()); } Map beansOfType = ((ListableBeanFactory)beanFactory).getBeansOfType(clz); if (log.isDebugEnabled()) { log.debug("beans: " + beansOfType + " - " + beansOfType.size()); } if (beansOfType.size() == 0) { log.debug("adding parameter the normal way"); super.addParameter(askFor, valueParam); } else if (beansOfType.size() > 1) { // TODO: handle multiple declarations throw new InstantiationException("multiple beans of type '" + clz.getName() + "' were found in the spring configuration"); } else { this.beans.put(askFor, beansOfType.values().iterator().next()); } } catch (ClassNotFoundException e) { super.addParameter(askFor, valueParam); } }
public Collection getBeanNames() { List names = new ArrayList(); // Snarf the beans from Spring if (beanFactory instanceof ListableBeanFactory) { ListableBeanFactory listable = (ListableBeanFactory) beanFactory; names.addAll(Arrays.asList(listable.getBeanDefinitionNames())); } else { log.warn("List of beanNames does not include Spring beans since your BeanFactory is not a ListableBeanFactory."); } // And append the DWR ones names.addAll(super.getBeanNames()); return Collections.unmodifiableCollection(names); }
/** * Register {@link DatastoreResolver}s bean into given <code>datastore</code>. * @param datastore Datastore * @param datastoreBeanName Datastore bean name * @param factory BeanFactory */ public static void configureDatastore(Datastore datastore, String datastoreBeanName, BeanFactory factory) { ObjectUtils.argumentNotNull(datastore, "Null Datastore"); ObjectUtils.argumentNotNull(datastoreBeanName, "Null Datastore bean name"); ObjectUtils.argumentNotNull(factory, "Null BeanFactory"); if (factory instanceof ListableBeanFactory) { configureDatastoreResolvers(datastore, datastoreBeanName, (ListableBeanFactory) factory); configureDatastoreCommodityFactories(datastore, datastoreBeanName, (ListableBeanFactory) factory); configureDatastorePostProcessors(datastore, datastoreBeanName, (ListableBeanFactory) factory); } else { LOGGER.warn( "The BeanFactory [" + factory + "] is not a ListableBeanFactory: skipping Datastore configuration"); } }
/** * Register {@link DatastoreResolver} annotated beans as <code>datastore</code> {@link ExpressionResolver}s. * @param datastore Datastore to configure * @param datastoreBeanName Datastore bean name to configure * @param beanFactory Bean factory */ private static void configureDatastoreResolvers(Datastore datastore, String datastoreBeanName, ListableBeanFactory beanFactory) { final String[] beanNames = beanFactory.getBeanNamesForAnnotation(DatastoreResolver.class); if (beanNames != null && beanNames.length > 0) { for (String beanName : beanNames) { if (!ExpressionResolver.class.isAssignableFrom(beanFactory.getType(beanName))) { throw new BeanNotOfRequiredTypeException(beanName, ExpressionResolver.class, beanFactory.getType(beanName)); } DatastoreResolver dr = beanFactory.findAnnotationOnBean(beanName, DatastoreResolver.class); String datastoreRef = AnnotationUtils.getStringValue(dr.datastoreBeanName()); if (datastoreRef == null || datastoreRef.equals(datastoreBeanName)) { // register resolver ExpressionResolver<?, ?> resolver = (ExpressionResolver<?, ?>) beanFactory.getBean(beanName); datastore.addExpressionResolver(resolver); LOGGER.debug(() -> "Registered expression resolver [" + resolver.getClass().getName() + "] into Datastore with bean name [" + datastoreBeanName + "]"); } } } }
@Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { if (beanFactory instanceof ListableBeanFactory) { String[] dataSourceBeanNames = ((ListableBeanFactory) beanFactory).getBeanNamesForType(DataSource.class, false, true); if (dataSourceBeanNames != null) { for (String dataSourceBeanName : dataSourceBeanNames) { BeanDefinition bd = registry.getBeanDefinition(dataSourceBeanName); if (bd instanceof DataContextBoundBeanDefinition) { DataSourceRegistrar.registerDataSourceTransactionManager(registry, dataSourceBeanName, ((DataContextBoundBeanDefinition) bd).getDataContextId().orElse(null), PrimaryMode.AUTO); } } } } }
@Override public void afterPropertiesSet() throws Exception { if (beanFactory instanceof ListableBeanFactory) { Map<String, HandlerMethodArgumentResolver> instances = ((ListableBeanFactory) this.beanFactory).getBeansOfType(HandlerMethodArgumentResolver.class); if (null != instances && instances.size() > 0) { handlerMethodArgumentResolvers.addAll(instances.values()); } } if (null == messageHandlerMethodFactory) { messageHandlerMethodFactory = createDefaultJmsHandlerMethodFactory(); } if (endpointRegistry instanceof JmsListenerEndpointRegistryAdapter) { JmsListenerEndpointRegistryAdapter methodEndpointRegistry = (JmsListenerEndpointRegistryAdapter) endpointRegistry; methodEndpointRegistry.setMessageHandlerMethodFactory(messageHandlerMethodFactory); } }
/** * 初始化Fetcher容器 * * @param factory */ public static void initFetcherContainer(ListableBeanFactory factory) { if (initing.get()) { waitInit(); return; } if (initing.compareAndSet(false, true)) { Map<String, Object> fetcherServices = factory.getBeansWithAnnotation(TaskService.class); for (Object service : fetcherServices.values()) { regiserOneService(service); } hasInit.countDown(); } else { waitInit(); } }
@PostConstruct public void customizedSupportedMediaTypes() { if (this.beanFactory instanceof ListableBeanFactory) { Map<String, RequestMappingHandlerAdapter> handlerAdapters = ((ListableBeanFactory) this.beanFactory) .getBeansOfType(RequestMappingHandlerAdapter.class); for (Entry<String, RequestMappingHandlerAdapter> entry : handlerAdapters .entrySet()) { RequestMappingHandlerAdapter handlerAdapter = entry.getValue(); for (HttpMessageConverter<?> converter : handlerAdapter .getMessageConverters()) { if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) { ((TypeConstrainedMappingJackson2HttpMessageConverter) converter) .setSupportedMediaTypes( Arrays.asList(MediaTypes.HAL_JSON, MediaType.APPLICATION_JSON)); } } } } }
@Bean public MetricManager metricManager() { String[] beanNames = ((ListableBeanFactory) beanFactory) .getBeanNamesForType(Metric.class); if (beanNames == null) { throw new RuntimeException( "At least 1 Metric bean must be specified"); } Metric[] metrics = new Metric[beanNames.length]; int i = 0; for (String metricName : beanNames) { metrics[i++] = beanFactory.getBean(metricName, Metric.class); } return new SimpleMetricManager(metrics); }
private void addServletContextInitializerBean(Class<?> type, String beanName, ServletContextInitializer initializer, ListableBeanFactory beanFactory, Object source) { this.initializers.add(type, initializer); if (source != null) { // Mark the underlying source as seen in case it wraps an existing bean this.seen.add(source); } if (ServletContextInitializerBeans.logger.isDebugEnabled()) { String resourceDescription = getResourceDescription(beanName, beanFactory); int order = getOrder(initializer); ServletContextInitializerBeans.logger.debug("Added existing " + type.getSimpleName() + " initializer bean '" + beanName + "'; order=" + order + ", resource=" + resourceDescription); } }
private <T, B extends T> void addAsRegistrationBean(ListableBeanFactory beanFactory, Class<T> type, Class<B> beanType, RegistrationBeanAdapter<T> adapter) { List<Map.Entry<String, B>> beans = getOrderedBeansOfType(beanFactory, beanType, this.seen); for (Entry<String, B> bean : beans) { if (this.seen.add(bean.getValue())) { int order = getOrder(bean.getValue()); String beanName = bean.getKey(); // One that we haven't already seen RegistrationBean registration = adapter.createRegistrationBean(beanName, bean.getValue(), beans.size()); registration.setName(beanName); registration.setOrder(order); this.initializers.add(type, registration); if (ServletContextInitializerBeans.logger.isDebugEnabled()) { ServletContextInitializerBeans.logger.debug( "Created " + type.getSimpleName() + " initializer for bean '" + beanName + "'; order=" + order + ", resource=" + getResourceDescription(beanName, beanFactory)); } } } }
private Map<String, JobFactory> loadFactories(ListableBeanFactory beanFactory) { ImmutableMap.Builder<String, JobFactory> mb = ImmutableMap.builder(); //load factory beans String[] factoryNames = beanFactory.getBeanNamesForType(JobFactory.class); for(String factoryName: factoryNames) { JobFactory factory = beanFactory.getBean(factoryName, JobFactory.class); if(factory == this) { // we do not want to load self continue; } Set<String> types = factory.getTypes(); for(String type: types) { mb.put(type, factory); } } //load job beans String[] jobNames = beanFactory.getBeanNamesForAnnotation(JobBean.class); for(String jobName: jobNames) { Class<?> jobType = beanFactory.getType(jobName); JobDescription jd = descFactory.getFor(jobName); mb.put(jobName, new JobFactoryForBean(this, jobName, jobType, jd)); } return mb.build(); }
/** * Returns a bean of specified type in the specified bean factory or its * ancestors. In contrast with Spring's BeanFactoryUtils, doesn't throw an * exception if no bean is found, but rather returns null. * * @param lbf * the bean factory to look for the bean * @param type * the expected type of the bean * @return the bean - if exactly one is defined. null - if none is defined * @throws NoSuchBeanDefinitionException * if more than one bean is defined */ public static <T> T beanOfTypeIncludingAncestors(final ListableBeanFactory lbf, final Class<T> type) { final Map<String, T> map = org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, type); switch (map.size()) { case 0: return null; case 1: return map.values().iterator().next(); default: throw new NoSuchBeanDefinitionException( "More than one bean of type " + type.getName() + " found: " + map.keySet()); } }
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { ListableBeanFactory listableBeanFactory = (ListableBeanFactory)beanFactory; // Find bean implementaing SupportsBackgroundIndexing and register for(Object bgindexable : listableBeanFactory.getBeansOfType(SupportsBackgroundIndexing.class).values()) { if(bgindexable instanceof SupportsBackgroundIndexing) { ((SupportsBackgroundIndexing)bgindexable).setFullTextSearchIndexer(this); } } }
@Override public void refresh() { super.refresh(); if (springContext != null) { Map<String, IExtensionPoint> extensionPointMap = new TreeMap<>(); extensionPointMap.putAll(springContext.getBeansOfType(IExtensionPoint.class)); if (springContext.getParentBeanFactory() != null && springContext.getParentBeanFactory() instanceof ListableBeanFactory) { extensionPointMap.putAll(((ListableBeanFactory) springContext.getParentBeanFactory()) .getBeansOfType(IExtensionPoint.class)); } log.info("Found {} extension points from spring that will be registered", extensionPointMap.size()); for (String name: extensionPointMap.keySet()) { registerExtension(name, extensionPointMap.get(name), true); } // Adding our extension to dynamically add product // in solr when a modification is synchronized by symmetricDS IExtensionPoint extension = (IExtensionPoint) ApplicationContextProvider.getBean( SolrReplicationExtensionPoint.class); registerExtension("symds", extension, true); } }
private Collection<String> getBeanNamesForType(ListableBeanFactory beanFactory, String type, ClassLoader classLoader, boolean considerHierarchy) throws LinkageError { try { Set<String> result = new LinkedHashSet<>(); collectBeanNamesForType(result, beanFactory, ClassUtils.forName(type, classLoader), considerHierarchy); return result; } catch (ClassNotFoundException | NoClassDefFoundError ex) { return Collections.emptySet(); } }
private void collectBeanNamesForType(Set<String> result, ListableBeanFactory beanFactory, Class<?> type, boolean considerHierarchy) { result.addAll(BeanTypeRegistry.get(beanFactory).getNamesForType(type)); if (considerHierarchy && beanFactory instanceof HierarchicalBeanFactory) { BeanFactory parent = ((HierarchicalBeanFactory) beanFactory).getParentBeanFactory(); if (parent instanceof ListableBeanFactory) { collectBeanNamesForType(result, (ListableBeanFactory) parent, type, considerHierarchy); } } }
private void collectBeanNamesForAnnotation(Set<String> names, ListableBeanFactory beanFactory, Class<? extends Annotation> annotationType, boolean considerHierarchy) { names.addAll(BeanTypeRegistry.get(beanFactory).getNamesForAnnotation(annotationType)); if (considerHierarchy) { BeanFactory parent = ((HierarchicalBeanFactory) beanFactory).getParentBeanFactory(); if (parent instanceof ListableBeanFactory) { collectBeanNamesForAnnotation(names, (ListableBeanFactory) parent, annotationType, considerHierarchy); } } }
public void testInterfacesHierarchy() { //Closeable.class, Class<?>[] clazz = ClassUtils.getAllInterfaces(DelegatedExecutionOsgiBundleApplicationContext.class); Class<?>[] expected = { ConfigurableOsgiBundleApplicationContext.class, ConfigurableApplicationContext.class, ApplicationContext.class, Lifecycle.class, Closeable.class, EnvironmentCapable.class, ListableBeanFactory.class, HierarchicalBeanFactory.class, MessageSource.class, ApplicationEventPublisher.class, ResourcePatternResolver.class, BeanFactory.class, ResourceLoader.class, AutoCloseable.class }; assertTrue(compareArrays(expected, clazz)); }
/** * This callback is only required for resolution of bean names in the * {@link #setBeans(java.util.Map) "beans"} {@link Map} and for * autodetection of MBeans (in the latter case, a * {@code ListableBeanFactory} is required). * @see #setBeans * @see #setAutodetect */ @Override public void setBeanFactory(BeanFactory beanFactory) { if (beanFactory instanceof ListableBeanFactory) { this.beanFactory = (ListableBeanFactory) beanFactory; } else { logger.info("MBeanExporter not running in a ListableBeanFactory: autodetection of MBeans not available."); } }
/** * Obtains all web service beans and publishes them as JAX-WS endpoints. */ @Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ListableBeanFactory)) { throw new IllegalStateException(getClass().getSimpleName() + " requires a ListableBeanFactory"); } this.beanFactory = (ListableBeanFactory) beanFactory; }
/** * Create a new PersistenceExceptionTranslationAdvisor. * @param beanFactory the ListableBeanFactory to obtaining all * PersistenceExceptionTranslators from * @param repositoryAnnotationType the annotation type to check for */ PersistenceExceptionTranslationAdvisor( ListableBeanFactory beanFactory, Class<? extends Annotation> repositoryAnnotationType) { this.advice = new PersistenceExceptionTranslationInterceptor(beanFactory); this.pointcut = new AnnotationMatchingPointcut(repositoryAnnotationType, true); }
@Override public void setBeanFactory(BeanFactory beanFactory) { if (!(beanFactory instanceof ListableBeanFactory)) { throw new IllegalArgumentException( "Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory"); } this.advisor = new PersistenceExceptionTranslationAdvisor( (ListableBeanFactory) beanFactory, this.repositoryAnnotationType); }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (this.persistenceExceptionTranslator == null) { // No explicit exception translator specified - perform autodetection. if (!(beanFactory instanceof ListableBeanFactory)) { throw new IllegalArgumentException( "Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory"); } this.beanFactory = (ListableBeanFactory) beanFactory; } }
/** * Detect all PersistenceExceptionTranslators in the given BeanFactory. * @param beanFactory the ListableBeanFactory to obtaining all * PersistenceExceptionTranslators from * @return a chained PersistenceExceptionTranslator, combining all * PersistenceExceptionTranslators found in the factory * @see ChainedPersistenceExceptionTranslator */ protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) { // Find all translators, being careful not to activate FactoryBeans. Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors( beanFactory, PersistenceExceptionTranslator.class, false, false); ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator(); for (PersistenceExceptionTranslator pet : pets.values()) { cpet.addDelegate(pet); } return cpet; }
@Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { if (!(beanFactory instanceof ListableBeanFactory)) { throw new FatalBeanException( "ServiceLocatorFactoryBean needs to run in a BeanFactory that is a ListableBeanFactory"); } this.beanFactory = (ListableBeanFactory) beanFactory; }