The SpringApplication class provides a convenient way to bootstrap a Spring application that is started from a main() method. In many situations, you can delegate to the static SpringApplication.run method, as shown in the following example:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
Class that can be used to bootstrap and launch a Spring application from a Java main method. By default class will perform the following steps to bootstrap your application:
#1. ApplicationContext 簡單來說就是存放管理的 Spring Bean 的容器 (Container) 。
#2. 什麼是CommandLinePropertySource?
CommandLinePropertySource is PropertySource subclass which is backed by command line arguments passed to a Java Application. (根據參考 CommandLinePropertySource’s Example)
如果單純查詢 PropertySource 的話,會發現有兩個 PropertySource ,兩個都包含於springframework 之內,但其中一個是類別寫作 PropertySource 屬於org.springframework.core.env 這一個包(原文 package),另一個是一個標籤 Annotation PropertySource 屬於org.springframework.context.annotation。
這裡回到 Class CommandLinePropertySource
Abstract base class for PropertySource implementations backed by command line arguments. The parameterized type T represents the underlying source of command line options. This may be as simple as a String array in the case of SimpleCommandLinePropertySource, or specific to a particular API such as JOpt's OptionSet in the case of JOptCommandLinePropertySource.
PropertySource 實作的抽象基底類別,透過由命令行參數支持,參數類型 T 代表 指令選項的底層資源。在 SimpleCommandLinePropertySource 的類別之中,參數類型T代表字串陣列,而在 JOptCommandLinePropertySource 的例子之中T代表特定API ,譬如 JOpt’s OptionSet 。
參考資料
{官方} Core features
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application
{官方} Class SpringApplication
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/SpringApplication.html
{官方} Class PropertySource
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html
CommandLinePropertySource’s Example
https://www.logicbig.com/tutorials/spring-framework/spring-core/command-line-property-source.html