By default, All Spring Boot application will display below banner on start up of application.
P.S Tested with spring boot 2.0.3.RELEASE
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.3.RELEASE)
We can disable the spring banner in various ways using banner-mode. Banner mode comes in three options.
console: Print the banner to System.out.
log: Print the banner to log file.
off: Disable printing off the banner.
1. Using Properties and YAML file
Set the property in the application.properties inside the resources folder of the spring boot project.
spring.main.banner-mode=off
Set the property in the application.yaml.
spring:
main:
banner-mode: 'off'
2. Programmatic Configuration
Spring boot provide an option to disable the banner programatically.
You can disable the banner by setting the properties in Map.
package com.walking.techie;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
public class HelloWorldApplication {
public static void main(String[] args) {
Map<String, Object> props = new HashMap<>();
props.put("spring.main.banner-mode", "off");
new SpringApplicationBuilder()
.sources(HelloWorldApplication.class)
.properties(props)
.run(args);
}
}
Or You can use setBannerMode method of SpringApplication class.
package com.walking.techie;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloWorldApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(HelloWorldApplication.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
}
}
4. Command Line
We can change the banner mode from terminal. When packaging and running our application as jar. We can set the spring.main.banner-mode argument with java command.
java -jar hello-world-1.0.jar --spring.main.banner-mode=off
Or With the equvalent syntax:
java -jar -Dspring.main.banner-mode=off hello-world-1.0.jar
No comments :
Post a Comment