Merge branch '1.3.x'
This commit is contained in:
		
						commit
						b6c509bd75
					
				|  | @ -43,8 +43,7 @@ class RabbitAnnotationDrivenConfiguration { | |||
| 	@Bean | ||||
| 	@ConditionalOnMissingBean | ||||
| 	public SimpleRabbitListenerContainerFactoryConfigurer rabbitListenerContainerFactoryConfigurer() { | ||||
| 		SimpleRabbitListenerContainerFactoryConfigurer configurer = | ||||
| 				new SimpleRabbitListenerContainerFactoryConfigurer(); | ||||
| 		SimpleRabbitListenerContainerFactoryConfigurer configurer = new SimpleRabbitListenerContainerFactoryConfigurer(); | ||||
| 		configurer.setRabbitProperties(this.properties); | ||||
| 		return configurer; | ||||
| 	} | ||||
|  | @ -54,8 +53,7 @@ class RabbitAnnotationDrivenConfiguration { | |||
| 	public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory( | ||||
| 			SimpleRabbitListenerContainerFactoryConfigurer configurer, | ||||
| 			ConnectionFactory connectionFactory) { | ||||
| 		SimpleRabbitListenerContainerFactory factory = | ||||
| 				new SimpleRabbitListenerContainerFactory(); | ||||
| 		SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | ||||
| 		configurer.configure(factory, connectionFactory); | ||||
| 		return factory; | ||||
| 	} | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ import org.springframework.cache.CacheManager; | |||
|  * Callback interface that can be implemented by beans wishing to customize the cache | ||||
|  * manager before it is fully initialized, in particular to tune its configuration. | ||||
|  * | ||||
|  * @param <C> The type of the {@link CacheManager} | ||||
|  * @author Stephane Nicoll | ||||
|  * @since 1.3.3 | ||||
|  */ | ||||
|  |  | |||
|  | @ -41,28 +41,30 @@ class CacheManagerCustomizerInvoker implements ApplicationContextAware { | |||
| 	private ConfigurableApplicationContext applicationContext; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Customize the specified {@link CacheManager}. Locates all {@link CacheManagerCustomizer} | ||||
| 	 * beans able to handle the specified instance and invoke | ||||
| 	 * {@link CacheManagerCustomizer#customize(CacheManager)} on them. | ||||
| 	 * Customize the specified {@link CacheManager}. Locates all | ||||
| 	 * {@link CacheManagerCustomizer} beans able to handle the specified instance and | ||||
| 	 * invoke {@link CacheManagerCustomizer#customize(CacheManager)} on them. | ||||
| 	 * @param cacheManager the cache manager to customize | ||||
| 	 */ | ||||
| 	public void customize(CacheManager cacheManager) { | ||||
| 		List<CacheManagerCustomizer<CacheManager>> customizers = findCustomizers(cacheManager); | ||||
| 		List<CacheManagerCustomizer<CacheManager>> customizers = findCustomizers( | ||||
| 				cacheManager); | ||||
| 		AnnotationAwareOrderComparator.sort(customizers); | ||||
| 		for (CacheManagerCustomizer<CacheManager> customizer : customizers) { | ||||
| 			customizer.customize(cacheManager); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	@SuppressWarnings("unchecked") | ||||
| 	private List<CacheManagerCustomizer<CacheManager>> findCustomizers(CacheManager cacheManager) { | ||||
| 	@SuppressWarnings({ "unchecked", "rawtypes" }) | ||||
| 	private List<CacheManagerCustomizer<CacheManager>> findCustomizers( | ||||
| 			CacheManager cacheManager) { | ||||
| 		if (this.applicationContext == null) { | ||||
| 			return Collections.emptyList(); | ||||
| 		} | ||||
| 		Map<String, CacheManagerCustomizer> map = BeanFactoryUtils | ||||
| 				.beansOfTypeIncludingAncestors(this.applicationContext.getBeanFactory(), CacheManagerCustomizer.class); | ||||
| 		List<CacheManagerCustomizer<CacheManager>> customizers | ||||
| 				= new ArrayList<CacheManagerCustomizer<CacheManager>>(); | ||||
| 				.beansOfTypeIncludingAncestors(this.applicationContext.getBeanFactory(), | ||||
| 						CacheManagerCustomizer.class); | ||||
| 		List<CacheManagerCustomizer<CacheManager>> customizers = new ArrayList<CacheManagerCustomizer<CacheManager>>(); | ||||
| 		for (CacheManagerCustomizer customizer : map.values()) { | ||||
| 			Class<?> target = GenericTypeResolver.resolveTypeArgument( | ||||
| 					customizer.getClass(), CacheManagerCustomizer.class); | ||||
|  | @ -73,9 +75,9 @@ class CacheManagerCustomizerInvoker implements ApplicationContextAware { | |||
| 		return customizers; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||||
| 	public void setApplicationContext(ApplicationContext applicationContext) | ||||
| 			throws BeansException { | ||||
| 		if (applicationContext instanceof ConfigurableApplicationContext) { | ||||
| 			this.applicationContext = (ConfigurableApplicationContext) applicationContext; | ||||
| 		} | ||||
|  |  | |||
|  | @ -41,10 +41,11 @@ import org.springframework.context.annotation.Import; | |||
|  * @see HazelcastConfigResourceCondition | ||||
|  */ | ||||
| @Configuration | ||||
| @ConditionalOnClass({HazelcastInstance.class, HazelcastCacheManager.class}) | ||||
| @ConditionalOnClass({ HazelcastInstance.class, HazelcastCacheManager.class }) | ||||
| @ConditionalOnMissingBean(CacheManager.class) | ||||
| @Conditional(CacheCondition.class) | ||||
| @Import({HazelcastInstanceConfiguration.Existing.class, HazelcastInstanceConfiguration.Specific.class}) | ||||
| @Import({ HazelcastInstanceConfiguration.Existing.class, | ||||
| 		HazelcastInstanceConfiguration.Specific.class }) | ||||
| class HazelcastCacheConfiguration { | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -61,7 +61,8 @@ abstract class HazelcastInstanceConfiguration { | |||
| 						location).getHazelcastInstance(); | ||||
| 				return new CloseableHazelcastCacheManager(cacheHazelcastInstance); | ||||
| 			} | ||||
| 			HazelcastCacheManager cacheManager = new HazelcastCacheManager(existingHazelcastInstance); | ||||
| 			HazelcastCacheManager cacheManager = new HazelcastCacheManager( | ||||
| 					existingHazelcastInstance); | ||||
| 			this.customizerInvoker.customize(cacheManager); | ||||
| 			return cacheManager; | ||||
| 		} | ||||
|  | @ -90,14 +91,14 @@ abstract class HazelcastInstanceConfiguration { | |||
| 
 | ||||
| 		@Bean | ||||
| 		public HazelcastCacheManager cacheManager() throws IOException { | ||||
| 			HazelcastCacheManager cacheManager = new HazelcastCacheManager(hazelcastInstance()); | ||||
| 			HazelcastCacheManager cacheManager = new HazelcastCacheManager( | ||||
| 					hazelcastInstance()); | ||||
| 			this.customizerInvoker.customize(cacheManager); | ||||
| 			return cacheManager; | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * {@link HazelcastConfigResourceCondition} that checks if the | ||||
| 	 * {@code spring.cache.hazelcast.config} configuration key is defined. | ||||
|  |  | |||
|  | @ -60,7 +60,8 @@ public class InfinispanCacheConfiguration { | |||
| 	@Bean | ||||
| 	public SpringEmbeddedCacheManager cacheManager( | ||||
| 			EmbeddedCacheManager embeddedCacheManager) { | ||||
| 		SpringEmbeddedCacheManager cacheManager = new SpringEmbeddedCacheManager(embeddedCacheManager); | ||||
| 		SpringEmbeddedCacheManager cacheManager = new SpringEmbeddedCacheManager( | ||||
| 				embeddedCacheManager); | ||||
| 		this.customizerInvoker.customize(cacheManager); | ||||
| 		return cacheManager; | ||||
| 	} | ||||
|  |  | |||
|  | @ -63,7 +63,6 @@ public final class DefaultJmsListenerContainerFactoryConfigurer { | |||
| 		this.jmsProperties = jmsProperties; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Configure the specified jms listener container factory. The factory can be further | ||||
| 	 * tuned and default settings can be overridden. | ||||
|  |  | |||
|  | @ -54,8 +54,7 @@ class JmsAnnotationDrivenConfiguration { | |||
| 	@Bean | ||||
| 	@ConditionalOnMissingBean | ||||
| 	public DefaultJmsListenerContainerFactoryConfigurer jmsListenerContainerFactoryConfigurer() { | ||||
| 		DefaultJmsListenerContainerFactoryConfigurer configurer = | ||||
| 				new DefaultJmsListenerContainerFactoryConfigurer(); | ||||
| 		DefaultJmsListenerContainerFactoryConfigurer configurer = new DefaultJmsListenerContainerFactoryConfigurer(); | ||||
| 		configurer.setDestinationResolver(this.destinationResolver); | ||||
| 		configurer.setTransactionManager(this.transactionManager); | ||||
| 		configurer.setJmsProperties(this.properties); | ||||
|  |  | |||
|  | @ -373,8 +373,10 @@ public class CacheAutoConfigurationTests { | |||
| 				HazelcastCacheManager.class); | ||||
| 		HazelcastInstance actual = getHazelcastInstance(cacheManager); | ||||
| 		assertThat(actual).isSameAs(hazelcastInstance); | ||||
| 		assertThat(actual.getConfig().getConfigurationUrl()).isEqualTo(new ClassPathResource( | ||||
| 				"org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml").getURL()); | ||||
| 		assertThat(actual.getConfig().getConfigurationUrl()) | ||||
| 				.isEqualTo(new ClassPathResource( | ||||
| 						"org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml") | ||||
| 								.getURL()); | ||||
| 		cacheManager.getCache("foobar"); | ||||
| 		assertThat(cacheManager.getCacheNames()).containsOnly("foobar"); | ||||
| 	} | ||||
|  | @ -583,13 +585,15 @@ public class CacheAutoConfigurationTests { | |||
| 		return type.cast(cacheManager); | ||||
| 	} | ||||
| 
 | ||||
| 	private void testCustomizers(Class<?> config, String cacheType, String... expectedCustomizerNames) { | ||||
| 	@SuppressWarnings("rawtypes") | ||||
| 	private void testCustomizers(Class<?> config, String cacheType, | ||||
| 			String... expectedCustomizerNames) { | ||||
| 		load(config, "spring.cache.type=" + cacheType); | ||||
| 		CacheManager cacheManager = validateCacheManager(CacheManager.class); | ||||
| 		List<String> expected = new ArrayList<String>(); | ||||
| 		expected.addAll(Arrays.asList(expectedCustomizerNames)); | ||||
| 		Map<String, CacheManagerTestCustomizer> map = | ||||
| 				this.context.getBeansOfType(CacheManagerTestCustomizer.class); | ||||
| 		Map<String, CacheManagerTestCustomizer> map = this.context | ||||
| 				.getBeansOfType(CacheManagerTestCustomizer.class); | ||||
| 		for (Map.Entry<String, CacheManagerTestCustomizer> entry : map.entrySet()) { | ||||
| 			if (expected.contains(entry.getKey())) { | ||||
| 				expected.remove(entry.getKey()); | ||||
|  | @ -611,7 +615,8 @@ public class CacheAutoConfigurationTests { | |||
| 		this.context = applicationContext; | ||||
| 	} | ||||
| 
 | ||||
| 	private static HazelcastInstance getHazelcastInstance(HazelcastCacheManager cacheManager) { | ||||
| 	private static HazelcastInstance getHazelcastInstance( | ||||
| 			HazelcastCacheManager cacheManager) { | ||||
| 		return (HazelcastInstance) new DirectFieldAccessor(cacheManager) | ||||
| 				.getPropertyValue("hazelcastInstance"); | ||||
| 	} | ||||
|  | @ -651,7 +656,8 @@ public class CacheAutoConfigurationTests { | |||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@Import({GenericCacheConfiguration.class, CacheManagerCustomizersConfiguration.class}) | ||||
| 	@Import({ GenericCacheConfiguration.class, | ||||
| 			CacheManagerCustomizersConfiguration.class }) | ||||
| 	static class GenericCacheAndCustomizersConfiguration { | ||||
| 	} | ||||
| 
 | ||||
|  | @ -667,7 +673,7 @@ public class CacheAutoConfigurationTests { | |||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@Import({RedisCacheConfiguration.class, CacheManagerCustomizersConfiguration.class}) | ||||
| 	@Import({ RedisCacheConfiguration.class, CacheManagerCustomizersConfiguration.class }) | ||||
| 	static class RedisCacheAndCustomizersConfiguration { | ||||
| 
 | ||||
| 	} | ||||
|  | @ -745,8 +751,8 @@ public class CacheAutoConfigurationTests { | |||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@ImportAutoConfiguration({CacheAutoConfiguration.class, | ||||
| 			HazelcastAutoConfiguration.class}) | ||||
| 	@ImportAutoConfiguration({ CacheAutoConfiguration.class, | ||||
| 			HazelcastAutoConfiguration.class }) | ||||
| 	static class HazelcastAndCacheConfiguration { | ||||
| 
 | ||||
| 	} | ||||
|  | @ -765,7 +771,7 @@ public class CacheAutoConfigurationTests { | |||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@Import({GenericCacheConfiguration.class, RedisCacheConfiguration.class}) | ||||
| 	@Import({ GenericCacheConfiguration.class, RedisCacheConfiguration.class }) | ||||
| 	static class CustomCacheManagerConfiguration { | ||||
| 
 | ||||
| 		@Bean | ||||
|  | @ -776,7 +782,7 @@ public class CacheAutoConfigurationTests { | |||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@Import({GenericCacheConfiguration.class, RedisCacheConfiguration.class}) | ||||
| 	@Import({ GenericCacheConfiguration.class, RedisCacheConfiguration.class }) | ||||
| 	static class CustomCacheManagerFromSupportConfiguration | ||||
| 			extends CachingConfigurerSupport { | ||||
| 
 | ||||
|  | @ -801,7 +807,7 @@ public class CacheAutoConfigurationTests { | |||
| 	} | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@Import({GenericCacheConfiguration.class, RedisCacheConfiguration.class}) | ||||
| 	@Import({ GenericCacheConfiguration.class, RedisCacheConfiguration.class }) | ||||
| 	static class CustomCacheResolverConfiguration extends CachingConfigurerSupport { | ||||
| 
 | ||||
| 		@Override | ||||
|  | @ -839,37 +845,44 @@ public class CacheAutoConfigurationTests { | |||
| 
 | ||||
| 		@Bean | ||||
| 		public CacheManagerCustomizer<SimpleCacheManager> genericCacheManagerCustomizer() { | ||||
| 			return new CacheManagerTestCustomizer<SimpleCacheManager>() { }; | ||||
| 			return new CacheManagerTestCustomizer<SimpleCacheManager>() { | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		@Bean | ||||
| 		public CacheManagerCustomizer<RedisCacheManager> redisCacheManagerCustomizer() { | ||||
| 			return new CacheManagerTestCustomizer<RedisCacheManager>() { }; | ||||
| 			return new CacheManagerTestCustomizer<RedisCacheManager>() { | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		@Bean | ||||
| 		public CacheManagerCustomizer<EhCacheCacheManager> ehCacheCacheManagerCustomizer() { | ||||
| 			return new CacheManagerTestCustomizer<EhCacheCacheManager>() { }; | ||||
| 			return new CacheManagerTestCustomizer<EhCacheCacheManager>() { | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		@Bean | ||||
| 		public CacheManagerCustomizer<HazelcastCacheManager> hazelcastCacheManagerCustomizer() { | ||||
| 			return new CacheManagerTestCustomizer<HazelcastCacheManager>() { }; | ||||
| 			return new CacheManagerTestCustomizer<HazelcastCacheManager>() { | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		@Bean | ||||
| 		public CacheManagerCustomizer<SpringEmbeddedCacheManager> infinispanCacheManagerCustomizer() { | ||||
| 			return new CacheManagerTestCustomizer<SpringEmbeddedCacheManager>() { }; | ||||
| 			return new CacheManagerTestCustomizer<SpringEmbeddedCacheManager>() { | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		@Bean | ||||
| 		public CacheManagerCustomizer<GuavaCacheManager> guavaCacheManagerCustomizer() { | ||||
| 			return new CacheManagerTestCustomizer<GuavaCacheManager>() { }; | ||||
| 			return new CacheManagerTestCustomizer<GuavaCacheManager>() { | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	static abstract class CacheManagerTestCustomizer<C extends CacheManager> implements CacheManagerCustomizer<C> { | ||||
| 	static abstract class CacheManagerTestCustomizer<C extends CacheManager> | ||||
| 			implements CacheManagerCustomizer<C> { | ||||
| 
 | ||||
| 		private C cacheManager; | ||||
| 
 | ||||
|  |  | |||
|  | @ -52,7 +52,8 @@ public class CacheManagerCustomizerInvokerTests { | |||
| 	@Test | ||||
| 	public void customizeSimpleCacheManager() { | ||||
| 		load(SimpleConfiguration.class, "spring.cache.type=simple"); | ||||
| 		ConcurrentMapCacheManager cacheManager = this.context.getBean(ConcurrentMapCacheManager.class); | ||||
| 		ConcurrentMapCacheManager cacheManager = this.context | ||||
| 				.getBean(ConcurrentMapCacheManager.class); | ||||
| 		assertThat(cacheManager.getCacheNames()).containsOnly("one", "two"); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -65,7 +66,6 @@ public class CacheManagerCustomizerInvokerTests { | |||
| 		verifyZeroInteractions(context); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	private void load(Class<?> config, String... environment) { | ||||
| 		AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); | ||||
| 		EnvironmentTestUtils.addEnvironment(applicationContext, environment); | ||||
|  | @ -75,7 +75,6 @@ public class CacheManagerCustomizerInvokerTests { | |||
| 		this.context = applicationContext; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	@Configuration | ||||
| 	@EnableCaching | ||||
| 	static class SimpleConfiguration { | ||||
|  |  | |||
|  | @ -459,8 +459,7 @@ public class JmsAutoConfigurationTests { | |||
| 		JmsListenerContainerFactory<?> customListenerContainerFactory( | ||||
| 				DefaultJmsListenerContainerFactoryConfigurer configurer, | ||||
| 				ConnectionFactory connectionFactory) { | ||||
| 			DefaultJmsListenerContainerFactory factory = | ||||
| 					new DefaultJmsListenerContainerFactory(); | ||||
| 			DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); | ||||
| 			configurer.configure(factory, connectionFactory); | ||||
| 			factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); | ||||
| 			return factory; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue