|
19 | 19 | import java.io.IOException;
|
20 | 20 | import java.io.UncheckedIOException;
|
21 | 21 | import java.time.Duration;
|
22 |
| -import java.util.Arrays; |
23 |
| -import java.util.List; |
24 |
| -import java.util.stream.Collectors; |
| 22 | +import java.util.Properties; |
25 | 23 |
|
26 | 24 | import org.springframework.aot.hint.RuntimeHints;
|
27 | 25 | import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
28 |
| -import org.springframework.beans.factory.config.PropertiesFactoryBean; |
29 | 26 | import org.springframework.boot.autoconfigure.AutoConfiguration;
|
30 | 27 | import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
31 | 28 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
45 | 42 | import org.springframework.context.support.AbstractApplicationContext;
|
46 | 43 | import org.springframework.context.support.ResourceBundleMessageSource;
|
47 | 44 | import org.springframework.core.Ordered;
|
48 |
| -import org.springframework.core.io.DefaultResourceLoader; |
49 | 45 | import org.springframework.core.io.Resource;
|
50 |
| -import org.springframework.core.io.ResourceLoader; |
51 | 46 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
| 47 | +import org.springframework.core.io.support.PropertiesLoaderUtils; |
52 | 48 | import org.springframework.core.type.AnnotatedTypeMetadata;
|
53 | 49 | import org.springframework.util.ConcurrentReferenceHashMap;
|
54 | 50 | import org.springframework.util.StringUtils;
|
@@ -91,19 +87,12 @@ public MessageSource messageSource(MessageSourceProperties properties) {
|
91 | 87 | messageSource.setUseCodeAsDefaultMessage(properties.isUseCodeAsDefaultMessage());
|
92 | 88 |
|
93 | 89 | try {
|
94 |
| - if (StringUtils.hasText(properties.getCommonMessages())) { |
95 |
| - PropertiesFactoryBean propertiesFactory = new PropertiesFactoryBean(); |
96 |
| - ResourceLoader resourceLoader = new DefaultResourceLoader(); |
97 |
| - String[] commonMessages = StringUtils.commaDelimitedListToStringArray( |
98 |
| - StringUtils.trimAllWhitespace(properties.getCommonMessages())); |
99 |
| - List<Resource> commonResources = Arrays.stream(commonMessages) |
100 |
| - .map(resourceLoader::getResource) |
101 |
| - .toList(); |
102 |
| - propertiesFactory.setLocations(commonResources.toArray(Resource[]::new)); |
103 |
| - propertiesFactory.setSingleton(true); |
104 |
| - propertiesFactory.setIgnoreResourceNotFound(true); |
105 |
| - propertiesFactory.afterPropertiesSet(); |
106 |
| - messageSource.setCommonMessages(propertiesFactory.getObject()); |
| 90 | + if (properties.getCommonMessages() != null) { |
| 91 | + Properties commonProperties = new Properties(); |
| 92 | + for (Resource commonResource : properties.getCommonMessages()) { |
| 93 | + PropertiesLoaderUtils.fillProperties(commonProperties, commonResource); |
| 94 | + } |
| 95 | + messageSource.setCommonMessages(commonProperties); |
107 | 96 | }
|
108 | 97 | } catch (IOException e) {
|
109 | 98 | throw new UncheckedIOException("Failed to load common messages", e);
|
|
0 commit comments