List of usage examples for org.springframework.beans.factory.config ConfigurableListableBeanFactory getSingleton
@Nullable Object getSingleton(String beanName);
From source file:org.alfresco.repo.management.subsystems.LegacyConfigPostProcessor.java
@SuppressWarnings("unchecked") public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { try {//from w ww .j a v a 2 s . c o m // Look up the global-properties bean and its locations list MutablePropertyValues globalProperties = beanFactory .getBeanDefinition(LegacyConfigPostProcessor.BEAN_NAME_GLOBAL_PROPERTIES).getPropertyValues(); PropertyValue pv = globalProperties.getPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS); Collection<Object> globalPropertyLocations; Object value; // Use the locations list if there is one, otherwise associate a new empty list if (pv != null && (value = pv.getValue()) != null && value instanceof Collection) { globalPropertyLocations = (Collection<Object>) value; } else { globalPropertyLocations = new ManagedList(10); globalProperties.addPropertyValue(LegacyConfigPostProcessor.PROPERTY_LOCATIONS, globalPropertyLocations); } // Move location paths added to repository-properties MutablePropertyValues repositoryProperties = processLocations(beanFactory, globalPropertyLocations, LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES, new String[] { "classpath:alfresco/version.properties" }); // Fix up additional properties to enforce correct order of precedence repositoryProperties.addPropertyValue("ignoreUnresolvablePlaceholders", Boolean.TRUE); repositoryProperties.addPropertyValue("localOverride", Boolean.FALSE); repositoryProperties.addPropertyValue("valueSeparator", null); repositoryProperties.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_NEVER"); // Move location paths added to hibernateConfigProperties MutablePropertyValues hibernateProperties = processLocations(beanFactory, globalPropertyLocations, LegacyConfigPostProcessor.BEAN_NAME_HIBERNATE_PROPERTIES, new String[] { "classpath:alfresco/domain/hibernate-cfg.properties", "classpath*:alfresco/enterprise/cache/hibernate-cfg.properties" }); // Fix up additional properties to enforce correct order of precedence hibernateProperties.addPropertyValue("localOverride", Boolean.TRUE); // Because Spring gets all post processors in one shot, the bean may already have been created. Let's try to // fix it up! PropertyPlaceholderConfigurer repositoryConfigurer = (PropertyPlaceholderConfigurer) beanFactory .getSingleton(LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES); if (repositoryConfigurer != null) { // Reset locations list repositoryConfigurer.setLocations(null); // Invalidate cached merged bean definitions ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition( LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES, beanFactory.getBeanDefinition(LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES)); // Reconfigure the bean according to its new definition beanFactory.configureBean(repositoryConfigurer, LegacyConfigPostProcessor.BEAN_NAME_REPOSITORY_PROPERTIES); } } catch (NoSuchBeanDefinitionException e) { // Ignore and continue } }