16
16
17
17
package org .springframework .cache .jcache ;
18
18
19
+ import javax .annotation .Resource ;
19
20
import javax .cache .CacheManager ;
20
21
import javax .cache .Caching ;
21
22
import javax .cache .configuration .MutableConfiguration ;
23
+ import javax .cache .spi .CachingProvider ;
22
24
23
25
import org .junit .After ;
24
26
import org .junit .Ignore ;
@@ -48,7 +50,10 @@ public class JCacheEhCacheTests extends AbstractAnnotationTests {
48
50
49
51
@ Override
50
52
protected ConfigurableApplicationContext getApplicationContext () {
51
- ConfigurableApplicationContext context = new AnnotationConfigApplicationContext (EnableCachingConfig .class );
53
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
54
+ context .getBeanFactory ().registerSingleton ("cachingProvider" , getCachingProvider ());
55
+ context .register (EnableCachingConfig .class );
56
+ context .refresh ();
52
57
jCacheManager = context .getBean ("jCacheManager" , CacheManager .class );
53
58
return context ;
54
59
}
@@ -68,10 +73,18 @@ public void testCustomCacheManager() {
68
73
}
69
74
70
75
76
+ protected CachingProvider getCachingProvider () {
77
+ return Caching .getCachingProvider ();
78
+ }
79
+
80
+
71
81
@ Configuration
72
82
@ EnableCaching
73
83
static class EnableCachingConfig extends CachingConfigurerSupport {
74
84
85
+ @ Resource
86
+ CachingProvider cachingProvider ;
87
+
75
88
@ Override
76
89
@ Bean
77
90
public org .springframework .cache .CacheManager cacheManager () {
@@ -80,7 +93,7 @@ public org.springframework.cache.CacheManager cacheManager() {
80
93
81
94
@ Bean
82
95
public CacheManager jCacheManager () {
83
- CacheManager cacheManager = Caching . getCachingProvider () .getCacheManager ();
96
+ CacheManager cacheManager = this . cachingProvider .getCacheManager ();
84
97
MutableConfiguration <Object , Object > mutableConfiguration = new MutableConfiguration <Object , Object >();
85
98
mutableConfiguration .setStoreByValue (false ); // otherwise value has to be Serializable
86
99
cacheManager .createCache ("testCache" , mutableConfiguration );
0 commit comments