Java 如何在标准输出中禁用 spring boot logo?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26585959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:52:22  来源:igfitidea点击:

how to disable spring boot logo in stdout?

javaspring-bootlogback

提问by Fabien Benoit-Koch

Is there a way to disable the lovely but very visible ASCII Spring boot logo :

有没有办法禁用可爱但非常明显的 ASCII Spring 引导标志:

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.1.8.RELEASE)

...dumped in STDOUT every time your run a spring boot app?

...每次运行 spring boot 应用程序时都在 STDOUT 中转储?

I switched all logging to ERROR in my logback.xml, but that did nothing:

我在 logback.xml 中将所有日志记录切换为 ERROR,但这没有任何作用:

<root level="ERROR">
    <appender-ref ref="STDOUT" />
</root>

edit: It's not called a "Logo" in the documentation. The search-friendly-term is a "banner".

编辑:它在文档中不被称为“徽标”。搜索友好的术语是一个“横幅”。

采纳答案by Evgeni Dimitrov

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-banner

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-banner

new SpringApplicationBuilder()
    .showBanner(false)
    .sources(Parent.class)
    .child(Application.class)
    .run(args);

EditIn the newer versions of spring boot(current is 1.3.3) the way to do it is:

编辑在较新版本的spring boot(当前是1.3.3)中,这样做的方法是:

1) application.properties

1) application.properties

spring.main.banner-mode=off

spring.main.banner-mode=off

2) application.yml

2) 应用程序.yml

spring:
    main:
        banner-mode: "off"

3) main method

3)主要方法

public static void main(String[] args) {
    SpringApplication app = new SpringApplication(MySpringConfiguration.class);
    app.setBannerMode(Banner.Mode.OFF);
    app.run(args);
}

Docs

文档

Edit:

编辑:

To change this with and environment variable use the property with underscore instead of dot. Try:

要使用环境变量更改此设置,请使用带下划线而不是点的属性。尝试:

SPRING_MAIN_BANNER-MODE=off

SPRING_MAIN_BANNER-MODE=关闭

See the docsfor externalized config.

有关外部化配置,请参阅文档

回答by Leonardo Dias

Another option is adding custom banner in a banner.txtfile to your classpath, that will change to your custom banner.

另一种选择是将banner.txt文件中的自定义横幅添加到您的类路径,这将更改为您的自定义横幅。

  1. create a file banner.txtin the classpath (i.e: src/main/resources)
  2. Edit you custom banner
  3. Run the application
  1. 在类路径中创建一个文件banner.txt(即:src/main/resources
  2. 编辑您的自定义横幅
  3. 运行应用程序

回答by Frank de Groot - Schouten

You can set spring.main.show_banner=falsein your application.propertiesas described in http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html.

你可以设置spring.main.show_banner=falseapplication.properties的描述http://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html

回答by Wim Deblauwe

This has changed slightly in Spring Boot 1.3. The property is now:

这在 Spring Boot 1.3 中略有改变。该物业现为:

spring.main.banner_mode=off

In code, it is now:

在代码中,它现在是:

springApplication.setBannerMode(Banner.Mode.OFF);

or using the builder:

或使用构建器:

new SpringApplicationBuilder()
.bannerMode(Banner.Mode.OFF)

回答by Rob

If you are using Spring Boot 1.3 and application.yml (not properties) then you need to quote the 'OFF' i.e.

如果您使用的是 Spring Boot 1.3 和 application.yml(不是属性),那么您需要引用“OFF”即

spring:
  main:
    banner_mode: 'OFF'

回答by Rob

create a file "application.yml" under src/main/resources" and paste the below code.That would do the job

在 src/main/resources 下创建一个文件“application.yml”并粘贴下面的代码。这将完成这项工作

spring:
    main:
        banner-mode: "off"

回答by Usman Yaqoob

You can use this code to remove banner

您可以使用此代码删除横幅

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication


public class SpringBootConsoleApplication {

    public static void main(String[] args) throws Exception {

        SpringApplication app = new SpringApplication(SpringBootConsoleApplication.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.run(args);

    }

}

回答by Vipul Gulhane

To remove this:

要删除它:

1) spring.main.banner-mode=off

1) spring.main.banner-mode=off

Add above line in the file

在文件中添加以上行

application.properties

OR

或者

2) USE this in Main java class

2) 在 Main java 类中使用它

setBannerMode(Banner.Mode.OFF);

OR

或者

3) in-app*.yml file

3) 应用内*.yml 文件

spring:
        main :
               banner-mode=off

User This Link for More Details

使用此链接了解更多详情

http://mytechnologythought.blogspot.com/2017/07/how-to-remove-spring-boot-banner.html

http://mytechnologythought.blogspot.com/2017/07/how-to-remove-spring-boot-banner.html