# 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`。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/74.-properties-and-configuration/74.2.-externalize-the-configuration-of-springapplication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
