Skip to content

Commit 077bcc1

Browse files
committed
Use {placeholder} instead of ${placeholder}
Closes gh-58
1 parent d20483f commit 077bcc1

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ The value is calculated as `http://{host}:{port}{contextRoot}`.
223223

224224
This provides a mapping to issuer-uri of https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.security.spring.security.oauth2.client.provider[the OAuth provider details].
225225

226-
* name `spring.security.oauth2.client.provider.${providerName}.issuer-uri` with a default `providerName` of `spring`. The `providerName` can be overridden with the `OAuth2ClientProviderIssuerUri.providerName` property.
226+
* name `spring.security.oauth2.client.provider.{providerName}.issuer-uri` with a default `providerName` of `spring`. The `providerName` can be overridden with the `OAuth2ClientProviderIssuerUri.providerName` property.
227227
* value `'http://127.0.0.1:' + port` which can be overriden with the `OAuth2ClientProviderIssuerUri.value` property
228228

229229
== Samples

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPortUrl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
@Target({ ElementType.METHOD, ElementType.TYPE })
6060
@Retention(RetentionPolicy.RUNTIME)
6161
@Documented
62-
@DynamicProperty(name = "${name}", value = "'http://${host}:' + port + '${contextRoot}'")
62+
@DynamicProperty(name = "{name}", value = "'http://{host}:' + port + '{contextRoot}'")
6363
public @interface DynamicPortUrl {
6464

6565
/**

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/DynamicPropertyRegistryPropertyFactory.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818

1919
import java.util.HashMap;
2020
import java.util.Map;
21+
import java.util.Properties;
2122
import java.util.function.Supplier;
2223

2324
import org.springframework.core.annotation.MergedAnnotation;
24-
import org.springframework.core.env.MapPropertySource;
25-
import org.springframework.core.env.MutablePropertySources;
26-
import org.springframework.core.env.PropertySourcesPropertyResolver;
2725
import org.springframework.expression.Expression;
2826
import org.springframework.expression.ExpressionParser;
2927
import org.springframework.expression.spel.standard.SpelExpressionParser;
28+
import org.springframework.util.PropertyPlaceholderHelper;
3029

3130
/**
3231
* Creates a {@link DynamicPropertyRegistryProperty} from the {@link DynamicProperty}
@@ -44,12 +43,11 @@ DynamicPropertyRegistryProperty createRegistryProperty(MergedAnnotation<DynamicP
4443
if (dynamicProperty == null) {
4544
return null;
4645
}
47-
MutablePropertySources propertySources = new MutablePropertySources();
48-
Map<String, Object> annotationProperties = collectAttributes(mergedAnnotation);
49-
propertySources.addFirst(new MapPropertySource("dynamicProperty", annotationProperties));
50-
PropertySourcesPropertyResolver propertyResolver = new PropertySourcesPropertyResolver(propertySources);
51-
String value = propertyResolver.resolvePlaceholders(dynamicProperty.value());
52-
String name = propertyResolver.resolvePlaceholders(dynamicProperty.name());
46+
Properties annotationProperties = new Properties();
47+
annotationProperties.putAll(collectAttributes(mergedAnnotation));
48+
PropertyPlaceholderHelper propertyResolver = new PropertyPlaceholderHelper("{", "}");
49+
String value = propertyResolver.replacePlaceholders(dynamicProperty.value(), annotationProperties);
50+
String name = propertyResolver.replacePlaceholders(dynamicProperty.name(), annotationProperties);
5351
Expression expression = this.parser.parseExpression(value);
5452
return new DynamicPropertyRegistryProperty(name, () -> expression.getValue(rootObject.get()));
5553
}

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/test/context/OAuth2ClientProviderIssuerUri.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626

2727
/**
2828
* A composed annotation for {@link DynamicProperty} for specifying the property name
29-
* "spring.security.oauth2.client.provider.${providerName}.issuer-uri" such that
29+
* "spring.security.oauth2.client.provider.{providerName}.issuer-uri" such that
3030
* providerName's value is specified by {@link #providerName()}.
3131
*
3232
* @author Rob Winch
3333
*/
3434
@Target(ElementType.METHOD)
3535
@Retention(RetentionPolicy.RUNTIME)
3636
@Documented
37-
@DynamicPortUrl(name = "spring.security.oauth2.client.provider.${providerName}.issuer-uri")
37+
@DynamicPortUrl(name = "spring.security.oauth2.client.provider.{providerName}.issuer-uri")
3838
public @interface OAuth2ClientProviderIssuerUri {
3939

4040
/**

spring-boot-testjars/src/test/java/org/springframework/experimental/boot/test/context/DynamicPropertyRegistryPropertyFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void dynamicPortUrlWithOverride() {
137137
}
138138

139139
@Retention(RetentionPolicy.RUNTIME)
140-
@DynamicProperty(name = "message", value = "'Hello ${firstName}'")
140+
@DynamicProperty(name = "message", value = "'Hello {firstName}'")
141141
@interface ValueWithVariable {
142142

143143
String firstName();

0 commit comments

Comments
 (0)