11/*
2- * Copyright 2012-2019 the original author or authors.
2+ * Copyright 2012-2023 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.
5757 */
5858public class ImageBanner implements Banner {
5959
60+ private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless" ;
61+
6062 private static final String PROPERTY_PREFIX = "spring.banner.image." ;
6163
6264 private static final Log logger = LogFactory .getLog (ImageBanner .class );
@@ -73,24 +75,17 @@ public ImageBanner(Resource image) {
7375
7476 @ Override
7577 public void printBanner (Environment environment , Class <?> sourceClass , PrintStream out ) {
76- String headless = System .getProperty ("java.awt.headless" );
7778 try {
78- System .setProperty ("java.awt.headless" , "true" );
79+ if (System .getProperty (SYSTEM_PROPERTY_JAVA_AWT_HEADLESS ) == null ) {
80+ System .setProperty (SYSTEM_PROPERTY_JAVA_AWT_HEADLESS , "true" );
81+ }
7982 printBanner (environment , out );
8083 }
8184 catch (Throwable ex ) {
8285 logger .warn (LogMessage .format ("Image banner not printable: %s (%s: '%s')" , this .image , ex .getClass (),
8386 ex .getMessage ()));
8487 logger .debug ("Image banner printing failure" , ex );
8588 }
86- finally {
87- if (headless == null ) {
88- System .clearProperty ("java.awt.headless" );
89- }
90- else {
91- System .setProperty ("java.awt.headless" , headless );
92- }
93- }
9489 }
9590
9691 private void printBanner (Environment environment , PrintStream out ) throws IOException {
0 commit comments