1
1
/*
2
- * Copyright 2012-2019 the original author or authors.
2
+ * Copyright 2012-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
57
57
*/
58
58
public class ImageBanner implements Banner {
59
59
60
+ private static final String SYSTEM_PROPERTY_JAVA_AWT_HEADLESS = "java.awt.headless" ;
61
+
60
62
private static final String PROPERTY_PREFIX = "spring.banner.image." ;
61
63
62
64
private static final Log logger = LogFactory .getLog (ImageBanner .class );
@@ -73,24 +75,17 @@ public ImageBanner(Resource image) {
73
75
74
76
@ Override
75
77
public void printBanner (Environment environment , Class <?> sourceClass , PrintStream out ) {
76
- String headless = System .getProperty ("java.awt.headless" );
77
78
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
+ }
79
82
printBanner (environment , out );
80
83
}
81
84
catch (Throwable ex ) {
82
85
logger .warn (LogMessage .format ("Image banner not printable: %s (%s: '%s')" , this .image , ex .getClass (),
83
86
ex .getMessage ()));
84
87
logger .debug ("Image banner printing failure" , ex );
85
88
}
86
- finally {
87
- if (headless == null ) {
88
- System .clearProperty ("java.awt.headless" );
89
- }
90
- else {
91
- System .setProperty ("java.awt.headless" , headless );
92
- }
93
- }
94
89
}
95
90
96
91
private void printBanner (Environment environment , PrintStream out ) throws IOException {
0 commit comments