Skip to content

Commit fae3cd1

Browse files
committed
Harmonize configuration properties that accept a list of values
Closes gh-42478
1 parent 6b216f1 commit fae3cd1

File tree

26 files changed

+171
-157
lines changed

26 files changed

+171
-157
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,34 +37,32 @@
3737
public class CorsEndpointProperties {
3838

3939
/**
40-
* Comma-separated list of origins to allow. '*' allows all origins. When credentials
41-
* are allowed, '*' cannot be used and origin patterns should be configured instead.
42-
* When no allowed origins or allowed origin patterns are set, CORS support is
43-
* disabled.
40+
* List of origins to allow. '*' allows all origins. When credentials are allowed, '*'
41+
* cannot be used and origin patterns should be configured instead. When no allowed
42+
* origins or allowed origin patterns are set, CORS support is disabled.
4443
*/
4544
private List<String> allowedOrigins = new ArrayList<>();
4645

4746
/**
48-
* Comma-separated list of origin patterns to allow. Unlike allowed origins which only
49-
* supports '*', origin patterns are more flexible (for example
50-
* 'https://*.example.com') and can be used when credentials are allowed. When no
51-
* allowed origin patterns or allowed origins are set, CORS support is disabled.
47+
* List of origin patterns to allow. Unlike allowed origins which only supports '*',
48+
* origin patterns are more flexible (for example 'https://*.example.com') and can be
49+
* used when credentials are allowed. When no allowed origin patterns or allowed
50+
* origins are set, CORS support is disabled.
5251
*/
5352
private List<String> allowedOriginPatterns = new ArrayList<>();
5453

5554
/**
56-
* Comma-separated list of methods to allow. '*' allows all methods. When not set,
57-
* defaults to GET.
55+
* List of methods to allow. '*' allows all methods. When not set, defaults to GET.
5856
*/
5957
private List<String> allowedMethods = new ArrayList<>();
6058

6159
/**
62-
* Comma-separated list of headers to allow in a request. '*' allows all headers.
60+
* List of headers to allow in a request. '*' allows all headers.
6361
*/
6462
private List<String> allowedHeaders = new ArrayList<>();
6563

6664
/**
67-
* Comma-separated list of headers to include in a response.
65+
* List of headers to include in a response.
6866
*/
6967
private List<String> exposedHeaders = new ArrayList<>();
7068

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void setRoles(Set<String> roles) {
7878
public static class Status {
7979

8080
/**
81-
* Comma-separated list of health statuses in order of severity.
81+
* List of health statuses in order of severity.
8282
*/
8383
private List<String> order = new ArrayList<>();
8484

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -200,7 +200,7 @@ public Diskspace getDiskspace() {
200200
public static class Diskspace {
201201

202202
/**
203-
* Comma-separated list of paths to report disk metrics for.
203+
* List of paths to report disk metrics for.
204204
*/
205205
private List<File> paths = new ArrayList<>(Collections.singletonList(new File(".")));
206206

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/PropertiesRabbitConnectionDetails.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public String getVirtualHost() {
5252
@Override
5353
public List<Address> getAddresses() {
5454
List<Address> addresses = new ArrayList<>();
55-
for (String address : this.properties.determineAddresses().split(",")) {
55+
for (String address : this.properties.determineAddresses()) {
5656
int portSeparatorIndex = address.lastIndexOf(':');
5757
String host = address.substring(0, portSeparatorIndex);
5858
String port = address.substring(portSeparatorIndex + 1);

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ public class RabbitProperties {
9292
private String virtualHost;
9393

9494
/**
95-
* Comma-separated list of addresses to which the client should connect. When set, the
96-
* host and port are ignored.
95+
* List of addresses to which the client should connect. When set, the host and port
96+
* are ignored.
9797
*/
98-
private String addresses;
98+
private List<String> addresses;
9999

100100
/**
101101
* Mode used to shuffle configured addresses.
@@ -163,7 +163,7 @@ public String getHost() {
163163
* Returns the host from the first address, or the configured host if no addresses
164164
* have been set.
165165
* @return the host
166-
* @see #setAddresses(String)
166+
* @see #setAddresses(List)
167167
* @see #getHost()
168168
*/
169169
public String determineHost() {
@@ -185,7 +185,7 @@ public Integer getPort() {
185185
* Returns the port from the first address, or the configured port if no addresses
186186
* have been set.
187187
* @return the port
188-
* @see #setAddresses(String)
188+
* @see #setAddresses(List)
189189
* @see #getPort()
190190
*/
191191
public int determinePort() {
@@ -203,38 +203,38 @@ public void setPort(Integer port) {
203203
this.port = port;
204204
}
205205

206-
public String getAddresses() {
206+
public List<String> getAddresses() {
207207
return this.addresses;
208208
}
209209

210210
/**
211-
* Returns the comma-separated addresses or a single address ({@code host:port})
212-
* created from the configured host and port if no addresses have been set.
211+
* Returns the configured addresses or a single address ({@code host:port}) created
212+
* from the configured host and port if no addresses have been set.
213213
* @return the addresses
214214
*/
215-
public String determineAddresses() {
215+
public List<String> determineAddresses() {
216216
if (CollectionUtils.isEmpty(this.parsedAddresses)) {
217217
if (this.host.contains(",")) {
218218
throw new InvalidConfigurationPropertyValueException("spring.rabbitmq.host", this.host,
219219
"Invalid character ','. Value must be a single host. For multiple hosts, use property 'spring.rabbitmq.addresses' instead.");
220220
}
221-
return this.host + ":" + determinePort();
221+
return List.of(this.host + ":" + determinePort());
222222
}
223223
List<String> addressStrings = new ArrayList<>();
224224
for (Address parsedAddress : this.parsedAddresses) {
225225
addressStrings.add(parsedAddress.host + ":" + parsedAddress.port);
226226
}
227-
return StringUtils.collectionToCommaDelimitedString(addressStrings);
227+
return addressStrings;
228228
}
229229

230-
public void setAddresses(String addresses) {
230+
public void setAddresses(List<String> addresses) {
231231
this.addresses = addresses;
232232
this.parsedAddresses = parseAddresses(addresses);
233233
}
234234

235-
private List<Address> parseAddresses(String addresses) {
235+
private List<Address> parseAddresses(List<String> addresses) {
236236
List<Address> parsedAddresses = new ArrayList<>();
237-
for (String address : StringUtils.commaDelimitedListToStringArray(addresses)) {
237+
for (String address : addresses) {
238238
parsedAddresses.add(new Address(address, Optional.ofNullable(getSsl().getEnabled()).orElse(false)));
239239
}
240240
return parsedAddresses;
@@ -248,7 +248,7 @@ public String getUsername() {
248248
* If addresses have been set and the first address has a username it is returned.
249249
* Otherwise returns the result of calling {@code getUsername()}.
250250
* @return the username
251-
* @see #setAddresses(String)
251+
* @see #setAddresses(List)
252252
* @see #getUsername()
253253
*/
254254
public String determineUsername() {
@@ -271,7 +271,7 @@ public String getPassword() {
271271
* If addresses have been set and the first address has a password it is returned.
272272
* Otherwise returns the result of calling {@code getPassword()}.
273273
* @return the password or {@code null}
274-
* @see #setAddresses(String)
274+
* @see #setAddresses(List)
275275
* @see #getPassword()
276276
*/
277277
public String determinePassword() {
@@ -298,7 +298,7 @@ public String getVirtualHost() {
298298
* If addresses have been set and the first address has a virtual host it is returned.
299299
* Otherwise returns the result of calling {@code getVirtualHost()}.
300300
* @return the virtual host or {@code null}
301-
* @see #setAddresses(String)
301+
* @see #setAddresses(List)
302302
* @see #getVirtualHost()
303303
*/
304304
public String determineVirtualHost() {
@@ -471,7 +471,7 @@ public Boolean getEnabled() {
471471
* Returns whether SSL is enabled from the first address, or the configured ssl
472472
* enabled flag if no addresses have been set.
473473
* @return whether ssl is enabled
474-
* @see #setAddresses(String)
474+
* @see #setAddresses(List)
475475
* @see #getEnabled() ()
476476
*/
477477
public boolean determineEnabled() {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheProperties.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,8 +41,8 @@ public class CacheProperties {
4141
private CacheType type;
4242

4343
/**
44-
* Comma-separated list of cache names to create if supported by the underlying cache
45-
* manager. Usually, this disables the ability to create additional caches on-the-fly.
44+
* List of cache names to create if supported by the underlying cache manager.
45+
* Usually, this disables the ability to create additional caches on-the-fly.
4646
*/
4747
private List<String> cacheNames = new ArrayList<>();
4848

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.core.io.Resource;
4343
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
4444
import org.springframework.core.type.AnnotatedTypeMetadata;
45+
import org.springframework.util.CollectionUtils;
4546
import org.springframework.util.ConcurrentReferenceHashMap;
4647
import org.springframework.util.StringUtils;
4748

@@ -67,9 +68,8 @@ public class MessageSourceAutoConfiguration {
6768
@Bean
6869
public MessageSource messageSource(MessageSourceProperties properties) {
6970
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
70-
if (StringUtils.hasText(properties.getBasename())) {
71-
messageSource.setBasenames(StringUtils
72-
.commaDelimitedListToStringArray(StringUtils.trimAllWhitespace(properties.getBasename())));
71+
if (!CollectionUtils.isEmpty(properties.getBasename())) {
72+
messageSource.setBasenames(properties.getBasename().toArray(new String[0]));
7373
}
7474
if (properties.getEncoding() != null) {
7575
messageSource.setDefaultEncoding(properties.getEncoding().name());

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/context/MessageSourceProperties.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.nio.charset.StandardCharsets;
2121
import java.time.Duration;
2222
import java.time.temporal.ChronoUnit;
23+
import java.util.ArrayList;
24+
import java.util.List;
2325

2426
import org.springframework.boot.context.properties.ConfigurationProperties;
2527
import org.springframework.boot.convert.DurationUnit;
@@ -35,12 +37,12 @@
3537
public class MessageSourceProperties {
3638

3739
/**
38-
* Comma-separated list of basenames (essentially a fully-qualified classpath
39-
* location), each following the ResourceBundle convention with relaxed support for
40-
* slash based locations. If it doesn't contain a package qualifier (such as
41-
* "org.mypackage"), it will be resolved from the classpath root.
40+
* List of basenames (essentially a fully-qualified classpath location), each
41+
* following the ResourceBundle convention with relaxed support for slash based
42+
* locations. If it doesn't contain a package qualifier (such as "org.mypackage"), it
43+
* will be resolved from the classpath root.
4244
*/
43-
private String basename = "messages";
45+
private List<String> basename = new ArrayList<>(List.of("messages"));
4446

4547
/**
4648
* Message bundles encoding.
@@ -73,11 +75,11 @@ public class MessageSourceProperties {
7375
*/
7476
private boolean useCodeAsDefaultMessage = false;
7577

76-
public String getBasename() {
78+
public List<String> getBasename() {
7779
return this.basename;
7880
}
7981

80-
public void setBasename(String basename) {
82+
public void setBasename(List<String> basename) {
8183
this.basename = basename;
8284
}
8385

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisProperties.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -322,8 +322,8 @@ public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) {
322322
public static class Cluster {
323323

324324
/**
325-
* Comma-separated list of "host:port" pairs to bootstrap from. This represents an
326-
* "initial" list of cluster nodes and is required to have at least one entry.
325+
* List of "host:port" pairs to bootstrap from. This represents an "initial" list
326+
* of cluster nodes and is required to have at least one entry.
327327
*/
328328
private List<String> nodes;
329329

@@ -362,7 +362,7 @@ public static class Sentinel {
362362
private String master;
363363

364364
/**
365-
* Comma-separated list of "host:port" pairs.
365+
* List of "host:port" pairs.
366366
*/
367367
private List<String> nodes;
368368

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@
3333
public class ElasticsearchProperties {
3434

3535
/**
36-
* Comma-separated list of the Elasticsearch instances to use.
36+
* List of the Elasticsearch instances to use.
3737
*/
3838
private List<String> uris = new ArrayList<>(Collections.singletonList("http://localhost:9200"));
3939

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ public class FlywayProperties {
319319
private Boolean skipExecutingMigrations;
320320

321321
/**
322-
* Ignore migrations that match this comma-separated list of patterns when validating
323-
* migrations. Requires Flyway Teams.
322+
* List of patterns that identify migrations to ignore when performing validation.
323+
* Requires Flyway Teams.
324324
*/
325325
private List<String> ignoreMigrationPatterns;
326326

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerProperties.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
4444
private Map<String, String> settings = new HashMap<>();
4545

4646
/**
47-
* Comma-separated list of template paths.
47+
* List of template paths.
4848
*/
4949
private String[] templateLoaderPath = new String[] { DEFAULT_TEMPLATE_LOADER_PATH };
5050

@@ -72,6 +72,10 @@ public String[] getTemplateLoaderPath() {
7272
return this.templateLoaderPath;
7373
}
7474

75+
public void setTemplateLoaderPath(String... templateLoaderPaths) {
76+
this.templateLoaderPath = templateLoaderPaths;
77+
}
78+
7579
public boolean isPreferFileSystemAccess() {
7680
return this.preferFileSystemAccess;
7781
}
@@ -80,8 +84,4 @@ public void setPreferFileSystemAccess(boolean preferFileSystemAccess) {
8084
this.preferFileSystemAccess = preferFileSystemAccess;
8185
}
8286

83-
public void setTemplateLoaderPath(String... templateLoaderPaths) {
84-
this.templateLoaderPath = templateLoaderPaths;
85-
}
86-
8787
}

0 commit comments

Comments
 (0)