3232
3333import org .springframework .boot .ansi .AnsiPropertySource ;
3434import org .springframework .core .env .ConfigurableEnvironment ;
35+ import org .springframework .core .env .EnumerablePropertySource ;
3536import org .springframework .core .env .Environment ;
3637import org .springframework .core .env .MapPropertySource ;
3738import org .springframework .core .env .MutablePropertySources ;
4142import org .springframework .core .log .LogMessage ;
4243import org .springframework .util .Assert ;
4344import org .springframework .util .StreamUtils ;
45+ import org .springframework .util .StringUtils ;
4446
4547/**
4648 * Banner implementation that prints from a source text {@link Resource}.
@@ -112,11 +114,11 @@ private MutablePropertySources createEmptyDefaultSources(Environment environment
112114 return emptyDefaultSources ;
113115 }
114116
115- private MapPropertySource getTitleSource (@ Nullable Class <?> sourceClass , @ Nullable String defaultValue ) {
117+ private MapWithNullsPropertySource getTitleSource (@ Nullable Class <?> sourceClass , @ Nullable String defaultValue ) {
116118 String applicationTitle = getApplicationTitle (sourceClass );
117- Map <String , Object > titleMap = Collections .singletonMap ("application.title" ,
119+ Map <String , @ Nullable Object > titleMap = Collections .singletonMap ("application.title" ,
118120 (applicationTitle != null ) ? applicationTitle : defaultValue );
119- return new MapPropertySource ("title" , titleMap );
121+ return new MapWithNullsPropertySource ("title" , titleMap );
120122 }
121123
122124 /**
@@ -134,14 +136,14 @@ private AnsiPropertySource getAnsiSource() {
134136 return new AnsiPropertySource ("ansi" , true );
135137 }
136138
137- private MapPropertySource getVersionSource (Environment environment , @ Nullable String defaultValue ) {
138- return new MapPropertySource ("version" , getVersionsMap (environment , defaultValue ));
139+ private MapWithNullsPropertySource getVersionSource (Environment environment , @ Nullable String defaultValue ) {
140+ return new MapWithNullsPropertySource ("version" , getVersionsMap (environment , defaultValue ));
139141 }
140142
141- private Map <String , Object > getVersionsMap (Environment environment , @ Nullable String defaultValue ) {
143+ private Map <String , @ Nullable Object > getVersionsMap (Environment environment , @ Nullable String defaultValue ) {
142144 String appVersion = getApplicationVersion (environment );
143145 String bootVersion = getBootVersion ();
144- Map <String , Object > versions = new HashMap <>();
146+ Map <String , @ Nullable Object > versions = new HashMap <>();
145147 versions .put ("application.version" , getVersionString (appVersion , false , defaultValue ));
146148 versions .put ("spring-boot.version" , getVersionString (bootVersion , false , defaultValue ));
147149 versions .put ("application.formatted-version" , getVersionString (appVersion , true , defaultValue ));
@@ -164,4 +166,30 @@ protected String getBootVersion() {
164166 return format ? " (v" + version + ")" : version ;
165167 }
166168
169+ /**
170+ * Like {@link MapPropertySource}, but allows {@code null} as map values.
171+ */
172+ private static class MapWithNullsPropertySource extends EnumerablePropertySource <Map <String , @ Nullable Object >> {
173+
174+ MapWithNullsPropertySource (String name , Map <String , @ Nullable Object > source ) {
175+ super (name , source );
176+ }
177+
178+ @ Override
179+ public String [] getPropertyNames () {
180+ return StringUtils .toStringArray (this .source .keySet ());
181+ }
182+
183+ @ Override
184+ public @ Nullable Object getProperty (String name ) {
185+ return this .source .get (name );
186+ }
187+
188+ @ Override
189+ public boolean containsProperty (String name ) {
190+ return this .source .containsKey (name );
191+ }
192+
193+ }
194+
167195}
0 commit comments