> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/74.-properties-and-configuration/74.2.-externalize-the-configuration-of-springapplication.md).

# 74.2. 外部化SpringApplication配置

SpringApplication已经被属性化（主要是setters），所以你可以在创建应用时使用它的Java API修改其行为，或者使用以`spring.main.*`为key的属性来外部化这些配置。比如，在`application.properties`中可能会有以下内容：

```java
spring.main.web-environment=false
spring.main.banner-mode=off
```

这样，Spring Boot在启动时将不会显示banner，并且该应用也不是一个web应用。

**注** 以上示例也展示在属性名中使用下划线（`_`）和中划线（`-`）的灵活绑定。

外部配置定义的属性会覆盖创建`ApplicationContext`时通过Java API指定的值，让我们看如下应用：

```java
new SpringApplicationBuilder()
    .bannerMode(Banner.Mode.OFF)
    .sources(demo.MyApp.class)
    .run(args);
```

并使用以下配置：

```
spring.main.sources=com.acme.Config,com.acme.ExtraConfig
spring.main.banner-mode=console
```

实际的应用将显示banner（被配置覆盖），并为`ApplicationContext`指定3个sources，依次为：`demo.MyApp`，`com.acme.Config`，`com.acme.ExtraConfig`。
