This commit is contained in:
Phillip Webb 2015-06-15 11:44:44 -07:00
parent d87f2713af
commit 49039c33ea
4 changed files with 16 additions and 18 deletions

View File

@ -28,20 +28,19 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
* @since 1.3.0
*/ */
abstract class CacheConfigFileCondition extends SpringBootCondition { abstract class CacheConfigFileCondition extends SpringBootCondition {
private final String name; private final String name;
private final String configPrefix; private final String prefix;
private final String[] resourceLocations; private final String[] resourceLocations;
public CacheConfigFileCondition(String name, String configPrefix, public CacheConfigFileCondition(String name, String prefix,
String... resourceLocations) { String... resourceLocations) {
this.name = name; this.name = name;
this.configPrefix = (configPrefix.endsWith(".") ? configPrefix : configPrefix + "."); this.prefix = (prefix.endsWith(".") ? prefix : prefix + ".");
this.resourceLocations = resourceLocations; this.resourceLocations = resourceLocations;
} }
@ -49,9 +48,9 @@ abstract class CacheConfigFileCondition extends SpringBootCondition {
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) { AnnotatedTypeMetadata metadata) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
context.getEnvironment(), this.configPrefix); context.getEnvironment(), this.prefix);
if (resolver.containsProperty("config")) { if (resolver.containsProperty("config")) {
return ConditionOutcome.match("A '" + this.configPrefix + ".config' " return ConditionOutcome.match("A '" + this.prefix + ".config' "
+ "property is specified"); + "property is specified");
} }
return getResourceOutcome(context, metadata); return getResourceOutcome(context, metadata);

View File

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.cache;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -63,8 +62,7 @@ public class CacheConfigFileConditionTests {
assertTrue(this.context.containsBean("foo")); assertTrue(this.context.containsBean("foo"));
} }
private void load(Class<?> config, private void load(Class<?> config, String... environment) {
String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment); EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.register(config); applicationContext.register(config);
@ -72,7 +70,6 @@ public class CacheConfigFileConditionTests {
this.context = applicationContext; this.context = applicationContext;
} }
@Configuration @Configuration
@Conditional(CacheConfigFileDefaultFileCondition.class) @Conditional(CacheConfigFileDefaultFileCondition.class)
static class DefaultFileConfiguration { static class DefaultFileConfiguration {
@ -93,16 +90,19 @@ public class CacheConfigFileConditionTests {
} }
} }
private static class CacheConfigFileDefaultFileCondition extends CacheConfigFileCondition { private static class CacheConfigFileDefaultFileCondition extends
CacheConfigFileCondition {
public CacheConfigFileDefaultFileCondition() { public CacheConfigFileDefaultFileCondition() {
super("test", "spring.cache.test.", "classpath:/ehcache.xml"); super("test", "spring.cache.test.", "classpath:/ehcache.xml");
} }
} }
private static class CacheConfigFileNoDefaultFileCondition extends CacheConfigFileCondition { private static class CacheConfigFileNoDefaultFileCondition extends
CacheConfigFileCondition {
public CacheConfigFileNoDefaultFileCondition() { public CacheConfigFileNoDefaultFileCondition() {
super("test", "spring.cache.test", "classpath:/this-cache-file-does-not-exist.xml"); super("test", "spring.cache.test",
"classpath:/this-cache-file-does-not-exist.xml");
} }
} }

View File

@ -8,14 +8,14 @@ class Example implements CommandLineRunner {
private MyService myService private MyService myService
void run(String... args) { void run(String... args) {
println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/retry.groovy')}" println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/retry.groovy')}"
} }
} }
@Service @Service
class MyService { class MyService {
static int count = 0 static int count = 0
@Retryable @Retryable
@ -26,5 +26,3 @@ class MyService {
return "World!" return "World!"
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2013 the original author or authors. * Copyright 2012-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,6 +26,7 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer;
* {@link CompilerAutoConfiguration} for Spring Retry. * {@link CompilerAutoConfiguration} for Spring Retry.
* *
* @author Dave Syer * @author Dave Syer
* @since 1.3.0
*/ */
public class SpringRetryCompilerAutoConfiguration extends CompilerAutoConfiguration { public class SpringRetryCompilerAutoConfiguration extends CompilerAutoConfiguration {