Fixed SPR issue reference and aligned exception messages
Issue: SPR-11592
This commit is contained in:
parent
9fc13e1d23
commit
90512f036b
|
@ -103,7 +103,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||||
* @param cacheOperationSources must not be {@code null}
|
* @param cacheOperationSources must not be {@code null}
|
||||||
*/
|
*/
|
||||||
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
|
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
|
||||||
Assert.notEmpty(cacheOperationSources);
|
Assert.notEmpty(cacheOperationSources, "At least 1 CacheOperationSource needs to be specified");
|
||||||
this.cacheOperationSource = (cacheOperationSources.length > 1 ?
|
this.cacheOperationSource = (cacheOperationSources.length > 1 ?
|
||||||
new CompositeCacheOperationSource(cacheOperationSources) : cacheOperationSources[0]);
|
new CompositeCacheOperationSource(cacheOperationSources) : cacheOperationSources[0]);
|
||||||
}
|
}
|
||||||
|
@ -131,8 +131,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
Assert.state(this.cacheManager != null, "'cacheManager' is required");
|
Assert.state(this.cacheManager != null, "Property 'cacheManager' is required");
|
||||||
Assert.state(this.cacheOperationSource != null, "The 'cacheOperationSources' property is required: " +
|
Assert.state(this.cacheOperationSource != null, "Property 'cacheOperationSources' is required: " +
|
||||||
"If there are no cacheable methods, then don't use a cache aspect.");
|
"If there are no cacheable methods, then don't use a cache aspect.");
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,9 @@ public abstract class CacheAspectSupport implements InitializingBean {
|
||||||
Collection<Cache> caches = new ArrayList<Cache>(cacheNames.size());
|
Collection<Cache> caches = new ArrayList<Cache>(cacheNames.size());
|
||||||
for (String cacheName : cacheNames) {
|
for (String cacheName : cacheNames) {
|
||||||
Cache cache = this.cacheManager.getCache(cacheName);
|
Cache cache = this.cacheManager.getCache(cacheName);
|
||||||
Assert.notNull(cache, "Cannot find cache named '" + cacheName + "' for " + operation);
|
if (cache == null) {
|
||||||
|
throw new IllegalArgumentException("Cannot find cache named '" + cacheName + "' for " + operation);
|
||||||
|
}
|
||||||
caches.add(cache);
|
caches.add(cache);
|
||||||
}
|
}
|
||||||
return caches;
|
return caches;
|
||||||
|
|
|
@ -66,9 +66,9 @@ public class CacheReproTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void spr11595GetSimple() {
|
public void spr11592GetSimple() {
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11595Config.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
|
||||||
Spr11595Service bean = context.getBean(Spr11595Service.class);
|
Spr11592Service bean = context.getBean(Spr11592Service.class);
|
||||||
Cache cache = context.getBean("cache", Cache.class);
|
Cache cache = context.getBean("cache", Cache.class);
|
||||||
|
|
||||||
String key = "1";
|
String key = "1";
|
||||||
|
@ -83,9 +83,9 @@ public class CacheReproTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void spr11595GetNeverCache(){
|
public void spr11592GetNeverCache(){
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11595Config.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
|
||||||
Spr11595Service bean = context.getBean(Spr11595Service.class);
|
Spr11592Service bean = context.getBean(Spr11592Service.class);
|
||||||
Cache cache = context.getBean("cache", Cache.class);
|
Cache cache = context.getBean("cache", Cache.class);
|
||||||
|
|
||||||
String key = "1";
|
String key = "1";
|
||||||
|
@ -179,7 +179,7 @@ public class CacheReproTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
public static class Spr11595Config {
|
public static class Spr11592Config {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CacheManager cacheManager() {
|
public CacheManager cacheManager() {
|
||||||
|
@ -195,14 +195,13 @@ public class CacheReproTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Spr11595Service service() {
|
public Spr11592Service service() {
|
||||||
return new Spr11595Service();
|
return new Spr11592Service();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class Spr11595Service {
|
public static class Spr11592Service {
|
||||||
|
|
||||||
@Cacheable("cache")
|
@Cacheable("cache")
|
||||||
public Object getSimple(String key) {
|
public Object getSimple(String key) {
|
||||||
|
|
Loading…
Reference in New Issue