Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c93ea54e
Commit
c93ea54e
authored
Feb 26, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
8b587a87
4fd778fe
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
57 additions
and
50 deletions
+57
-50
CacheAutoConfiguration.java
...work/boot/autoconfigure/cache/CacheAutoConfiguration.java
+1
-1
CacheManagerCustomizer.java
...work/boot/autoconfigure/cache/CacheManagerCustomizer.java
+3
-3
CacheManagerCustomizers.java
...ork/boot/autoconfigure/cache/CacheManagerCustomizers.java
+21
-11
EhCacheCacheConfiguration.java
...k/boot/autoconfigure/cache/EhCacheCacheConfiguration.java
+2
-4
GenericCacheConfiguration.java
...k/boot/autoconfigure/cache/GenericCacheConfiguration.java
+2
-3
GuavaCacheConfiguration.java
...ork/boot/autoconfigure/cache/GuavaCacheConfiguration.java
+2
-3
HazelcastInstanceConfiguration.java
...t/autoconfigure/cache/HazelcastInstanceConfiguration.java
+4
-6
InfinispanCacheConfiguration.java
...oot/autoconfigure/cache/InfinispanCacheConfiguration.java
+2
-3
JCacheCacheConfiguration.java
...rk/boot/autoconfigure/cache/JCacheCacheConfiguration.java
+2
-3
RedisCacheConfiguration.java
...ork/boot/autoconfigure/cache/RedisCacheConfiguration.java
+2
-3
SimpleCacheConfiguration.java
...rk/boot/autoconfigure/cache/SimpleCacheConfiguration.java
+2
-3
CacheAutoConfigurationTests.java
...boot/autoconfigure/cache/CacheAutoConfigurationTests.java
+8
-5
CacheManagerCustomizersTests.java
...oot/autoconfigure/cache/CacheManagerCustomizersTests.java
+5
-2
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+1
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfiguration.java
View file @
c93ea54e
...
...
@@ -66,7 +66,7 @@ import org.springframework.util.Assert;
@EnableConfigurationProperties
(
CacheProperties
.
class
)
@AutoConfigureBefore
(
HibernateJpaAutoConfiguration
.
class
)
@AutoConfigureAfter
({
HazelcastAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
})
@Import
({
CacheManagerCustomizer
Invoker
.
class
,
CacheConfigurationImportSelector
.
class
})
@Import
({
CacheManagerCustomizer
s
.
class
,
CacheConfigurationImportSelector
.
class
})
public
class
CacheAutoConfiguration
{
static
final
String
VALIDATOR_BEAN_NAME
=
"cacheAutoConfigurationValidator"
;
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheManagerCustomizer.java
View file @
c93ea54e
...
...
@@ -22,16 +22,16 @@ 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}
* @param <
T
> The type of the {@link CacheManager}
* @author Stephane Nicoll
* @since 1.3.3
*/
public
interface
CacheManagerCustomizer
<
C
extends
CacheManager
>
{
public
interface
CacheManagerCustomizer
<
T
extends
CacheManager
>
{
/**
* Customize the cache manager.
* @param cacheManager the {@code CacheManager} to customize
*/
void
customize
(
C
cacheManager
);
void
customize
(
T
cacheManager
);
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheManagerCustomizer
Invoker
.java
→
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheManagerCustomizer
s
.java
View file @
c93ea54e
...
...
@@ -17,9 +17,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
cache
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
...
...
@@ -31,12 +31,12 @@ import org.springframework.core.GenericTypeResolver;
import
org.springframework.core.annotation.AnnotationAwareOrderComparator
;
/**
* Invoke the available {@link CacheManagerCustomizer} instances in the context for a
* Invoke
s
the available {@link CacheManagerCustomizer} instances in the context for a
* given {@link CacheManager}.
*
* @author Stephane Nicoll
*/
class
CacheManagerCustomizer
Invoker
implements
ApplicationContextAware
{
class
CacheManagerCustomizer
s
implements
ApplicationContextAware
{
private
ConfigurableApplicationContext
applicationContext
;
...
...
@@ -45,14 +45,16 @@ class CacheManagerCustomizerInvoker implements ApplicationContextAware {
* {@link CacheManagerCustomizer} beans able to handle the specified instance and
* invoke {@link CacheManagerCustomizer#customize(CacheManager)} on them.
* @param cacheManager the cache manager to customize
* @return the cache manager
*/
public
void
customize
(
CacheManager
cacheManager
)
{
public
<
T
extends
CacheManager
>
T
customize
(
T
cacheManager
)
{
List
<
CacheManagerCustomizer
<
CacheManager
>>
customizers
=
findCustomizers
(
cacheManager
);
AnnotationAwareOrderComparator
.
sort
(
customizers
);
for
(
CacheManagerCustomizer
<
CacheManager
>
customizer
:
customizers
)
{
customizer
.
customize
(
cacheManager
);
}
return
cacheManager
;
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
...
...
@@ -61,20 +63,28 @@ class CacheManagerCustomizerInvoker implements ApplicationContextAware {
if
(
this
.
applicationContext
==
null
)
{
return
Collections
.
emptyList
();
}
Map
<
String
,
CacheManagerCustomizer
>
map
=
BeanFactoryUtils
.
beansOfTypeIncludingAncestors
(
this
.
applicationContext
.
getBeanFactory
(),
CacheManagerCustomizer
.
class
);
Class
<?>
cacheManagerClass
=
cacheManager
.
getClass
();
List
<
CacheManagerCustomizer
<
CacheManager
>>
customizers
=
new
ArrayList
<
CacheManagerCustomizer
<
CacheManager
>>();
for
(
CacheManagerCustomizer
customizer
:
map
.
values
())
{
Class
<?>
target
=
GenericTypeResolver
.
resolveTypeArgument
(
customizer
.
getClass
(),
CacheManagerCustomizer
.
class
);
if
(
target
==
null
||
target
.
isAssignableFrom
(
cacheManager
.
getClass
()))
{
for
(
CacheManagerCustomizer
customizer
:
getBeans
(
CacheManagerCustomizer
.
class
))
{
if
(
canCustomize
(
customizer
,
cacheManagerClass
))
{
customizers
.
add
(
customizer
);
}
}
return
customizers
;
}
private
<
T
>
Collection
<
T
>
getBeans
(
Class
<
T
>
type
)
{
return
BeanFactoryUtils
.
beansOfTypeIncludingAncestors
(
this
.
applicationContext
.
getBeanFactory
(),
type
).
values
();
}
private
boolean
canCustomize
(
CacheManagerCustomizer
<?>
customizer
,
Class
<?>
cacheManagerClass
)
{
Class
<?>
target
=
GenericTypeResolver
.
resolveTypeArgument
(
customizer
.
getClass
(),
CacheManagerCustomizer
.
class
);
return
(
target
==
null
||
target
.
isAssignableFrom
(
cacheManagerClass
));
}
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -49,13 +49,11 @@ class EhCacheCacheConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Bean
public
EhCacheCacheManager
cacheManager
(
CacheManager
ehCacheCacheManager
)
{
EhCacheCacheManager
cacheManager
=
new
EhCacheCacheManager
(
ehCacheCacheManager
);
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
new
EhCacheCacheManager
(
ehCacheCacheManager
));
}
@Bean
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/GenericCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -42,14 +42,13 @@ import org.springframework.context.annotation.Configuration;
class
GenericCacheConfiguration
{
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Bean
public
SimpleCacheManager
cacheManager
(
Collection
<
Cache
>
caches
)
{
SimpleCacheManager
cacheManager
=
new
SimpleCacheManager
();
cacheManager
.
setCaches
(
caches
);
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
cacheManager
);
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/GuavaCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -49,7 +49,7 @@ class GuavaCacheConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Autowired
(
required
=
false
)
private
CacheBuilder
<
Object
,
Object
>
cacheBuilder
;
...
...
@@ -67,8 +67,7 @@ class GuavaCacheConfiguration {
if
(!
CollectionUtils
.
isEmpty
(
cacheNames
))
{
cacheManager
.
setCacheNames
(
cacheNames
);
}
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
cacheManager
);
}
private
GuavaCacheManager
createCacheManager
()
{
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastInstanceConfiguration.java
View file @
c93ea54e
...
...
@@ -49,7 +49,7 @@ abstract class HazelcastInstanceConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Bean
public
HazelcastCacheManager
cacheManager
(
...
...
@@ -63,8 +63,7 @@ abstract class HazelcastInstanceConfiguration {
}
HazelcastCacheManager
cacheManager
=
new
HazelcastCacheManager
(
existingHazelcastInstance
);
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
cacheManager
);
}
}
...
...
@@ -77,7 +76,7 @@ abstract class HazelcastInstanceConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Bean
public
HazelcastInstance
hazelcastInstance
()
throws
IOException
{
...
...
@@ -93,8 +92,7 @@ abstract class HazelcastInstanceConfiguration {
public
HazelcastCacheManager
cacheManager
()
throws
IOException
{
HazelcastCacheManager
cacheManager
=
new
HazelcastCacheManager
(
hazelcastInstance
());
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
cacheManager
);
}
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/InfinispanCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -52,7 +52,7 @@ public class InfinispanCacheConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Autowired
(
required
=
false
)
private
ConfigurationBuilder
defaultConfigurationBuilder
;
...
...
@@ -62,8 +62,7 @@ public class InfinispanCacheConfiguration {
EmbeddedCacheManager
embeddedCacheManager
)
{
SpringEmbeddedCacheManager
cacheManager
=
new
SpringEmbeddedCacheManager
(
embeddedCacheManager
);
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
cacheManager
);
}
@Bean
(
destroyMethod
=
"stop"
)
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -64,7 +64,7 @@ class JCacheCacheConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizers
;
@Autowired
(
required
=
false
)
private
javax
.
cache
.
configuration
.
Configuration
<?,
?>
defaultCacheConfiguration
;
...
...
@@ -75,8 +75,7 @@ class JCacheCacheConfiguration {
@Bean
public
JCacheCacheManager
cacheManager
(
CacheManager
jCacheCacheManager
)
{
JCacheCacheManager
cacheManager
=
new
JCacheCacheManager
(
jCacheCacheManager
);
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizers
.
customize
(
cacheManager
);
}
@Bean
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -47,7 +47,7 @@ class RedisCacheConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizerInvoker
;
@Bean
public
RedisCacheManager
cacheManager
(
RedisTemplate
<
Object
,
Object
>
redisTemplate
)
{
...
...
@@ -57,8 +57,7 @@ class RedisCacheConfiguration {
if
(!
cacheNames
.
isEmpty
())
{
cacheManager
.
setCacheNames
(
cacheNames
);
}
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizerInvoker
.
customize
(
cacheManager
);
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java
View file @
c93ea54e
...
...
@@ -41,7 +41,7 @@ class SimpleCacheConfiguration {
private
CacheProperties
cacheProperties
;
@Autowired
CacheManagerCustomizerInvoker
customizerInvoker
;
private
CacheManagerCustomizers
customizerInvoker
;
@Bean
public
ConcurrentMapCacheManager
cacheManager
()
{
...
...
@@ -50,8 +50,7 @@ class SimpleCacheConfiguration {
if
(!
cacheNames
.
isEmpty
())
{
cacheManager
.
setCacheNames
(
cacheNames
);
}
this
.
customizerInvoker
.
customize
(
cacheManager
);
return
cacheManager
;
return
this
.
customizerInvoker
.
customize
(
cacheManager
);
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java
View file @
c93ea54e
...
...
@@ -454,8 +454,10 @@ public class CacheAutoConfigurationTests {
load
(
DefaultCacheConfiguration
.
class
,
"spring.cache.type=jcache"
,
"spring.cache.jcache.provider="
+
cachingProviderFqn
,
"spring.cache.cacheNames[0]=foo"
,
"spring.cache.cacheNames[1]=bar"
);
JCacheCacheManager
cacheManager
=
validateCacheManager
(
JCacheCacheManager
.
class
);
JCacheCacheManager
cacheManager
=
validateCacheManager
(
JCacheCacheManager
.
class
);
assertThat
(
cacheManager
.
getCacheNames
()).
containsOnly
(
"foo"
,
"bar"
);
assertThat
(
cacheManager
.
getCacheNames
()).
hasSize
(
2
);
}
finally
{
Caching
.
getCachingProvider
(
cachingProviderFqn
).
close
();
...
...
@@ -889,18 +891,19 @@ public class CacheAutoConfigurationTests {
}
static
abstract
class
CacheManagerTestCustomizer
<
C
extends
CacheManager
>
implements
CacheManagerCustomizer
<
C
>
{
static
abstract
class
CacheManagerTestCustomizer
<
T
extends
CacheManager
>
implements
CacheManagerCustomizer
<
T
>
{
private
C
cacheManager
;
private
T
cacheManager
;
@Override
public
void
customize
(
C
cacheManager
)
{
public
void
customize
(
T
cacheManager
)
{
if
(
this
.
cacheManager
!=
null
)
{
throw
new
IllegalStateException
(
"Customized invoked twice"
);
}
this
.
cacheManager
=
cacheManager
;
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheManagerCustomizer
Invoker
Tests.java
→
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheManagerCustomizer
s
Tests.java
View file @
c93ea54e
...
...
@@ -38,7 +38,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
*
* @author Stephane Nicoll
*/
public
class
CacheManagerCustomizer
Invoker
Tests
{
public
class
CacheManagerCustomizer
s
Tests
{
private
AnnotationConfigApplicationContext
context
;
...
...
@@ -59,7 +59,7 @@ public class CacheManagerCustomizerInvokerTests {
@Test
public
void
customizeNoConfigurableApplicationContext
()
{
CacheManagerCustomizer
Invoker
invoker
=
new
CacheManagerCustomizerInvoker
();
CacheManagerCustomizer
s
invoker
=
new
CacheManagerCustomizers
();
ApplicationContext
context
=
mock
(
ApplicationContext
.
class
);
invoker
.
setApplicationContext
(
context
);
invoker
.
customize
(
mock
(
CacheManager
.
class
));
...
...
@@ -82,11 +82,14 @@ public class CacheManagerCustomizerInvokerTests {
@Bean
public
CacheManagerCustomizer
<
ConcurrentMapCacheManager
>
cacheManagerCustomizer
()
{
return
new
CacheManagerCustomizer
<
ConcurrentMapCacheManager
>()
{
@Override
public
void
customize
(
ConcurrentMapCacheManager
cacheManager
)
{
cacheManager
.
setCacheNames
(
Arrays
.
asList
(
"one"
,
"two"
));
}
};
}
}
}
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
c93ea54e
...
...
@@ -3280,6 +3280,7 @@ as you want and you can also order them as usual using `@Order` or `Ordered`.
===
[[boot-features-caching-provider-generic]]
==== Generic
Generic caching is used if the context defines _at least_ one
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment