public class SpringApplication extends ObjectSE
ApplicationContext
インスタンスを作成します (クラスパスに応じて)CommandLinePropertySource
を登録して、コマンドライン引数を Spring プロパティとして公開します CommandLineRunner
Bean をトリガーしますrun(Class, String[])
をメインメソッドから直接呼び出して、アプリケーションをブートストラップできます。@Configuration @EnableAutoConfiguration public class MyApplication { // ... Bean definitions public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
より高度な構成の場合、実行前に SpringApplication
インスタンスを作成およびカスタマイズできます。
public static void main(String[] args) { SpringApplication application = new SpringApplication(MyApplication.class); // ... customize application settings here application.run(args) }
SpringApplication
は、さまざまなソースから Bean を読み取ることができます。一般に、単一の @Configuration
クラスを使用してアプリケーションをブートストラップすることをお勧めしますが、sources
を以下から設定することもできます。AnnotatedBeanDefinitionReader
によってロードされる完全修飾クラス名 XmlBeanDefinitionReader
によってロードされる XML リソースの場所、または GroovyBeanDefinitionReader
によってロードされる groovy スクリプト ClassPathBeanDefinitionScanner
によってスキャンされるパッケージの名前SpringApplication
にバインドされます。これにより、追加のソース("spring.main.sources" -CSV リスト)のように、SpringApplication
プロパティを動的に設定して、Web 環境を示すフラグ("spring.main.web-application-type = none")やバナーをオフにするフラグを設定できます。("spring.main.banner-mode = off")。run(Class, String[])
, run(Class[], String[])
, SpringApplication(Class...)
修飾子と型 | フィールドと説明 |
---|---|
static StringSE | BANNER_LOCATION_PROPERTY バナーの場所のプロパティキー。 |
static StringSE | BANNER_LOCATION_PROPERTY_VALUE デフォルトのバナーの場所。 |
static StringSE | DEFAULT_CONTEXT_CLASS 非 Web 環境でデフォルトで使用されるアプリケーションコンテキストのクラス名。 |
static StringSE | DEFAULT_REACTIVE_WEB_CONTEXT_CLASS リアクティブ Web 環境でデフォルトで使用されるアプリケーションコンテキストのクラス名。 |
static StringSE | DEFAULT_SERVLET_WEB_CONTEXT_CLASS Web 環境でデフォルトで使用されるアプリケーションコンテキストのクラス名。 |
コンストラクターと説明 |
---|
SpringApplication(ClassSE<?>... primarySources) 新しい SpringApplication インスタンスを作成します。 |
SpringApplication(org.springframework.core.io.ResourceLoader resourceLoader, ClassSE<?>... primarySources) 新しい SpringApplication インスタンスを作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
void | addInitializers(org.springframework.context.ApplicationContextInitializer<?>... initializers) Spring ApplicationContext に適用される ApplicationContextInitializer を追加します。 |
void | addListeners(org.springframework.context.ApplicationListener<?>... listeners) ApplicationListener を追加して SpringApplication に適用し、ApplicationContext に登録します。 |
void | addPrimarySources(CollectionSE<ClassSE<?>> additionalPrimarySources) run(String...) が呼び出されたときに ApplicationContext に追加されるプライマリソースに追加のアイテムを追加します。 |
protected void | afterRefresh(org.springframework.context.ConfigurableApplicationContext context, ApplicationArguments args) コンテキストがリフレッシュされた後に呼び出されます。 |
protected void | applyInitializers(org.springframework.context.ConfigurableApplicationContext context) リフレッシュされる前に、 ApplicationContextInitializer をコンテキストに適用します。 |
protected void | bindToSpringApplication(org.springframework.core.env.ConfigurableEnvironment environment) 環境を SpringApplication にバインドします。 |
protected void | configureEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, StringSE[] args) |
protected void | configureProfiles(org.springframework.core.env.ConfigurableEnvironment environment, StringSE[] args) このアプリケーション環境でアクティブにするプロファイル(またはデフォルトでアクティブにするプロファイル)を構成します。 |
protected void | configurePropertySources(org.springframework.core.env.ConfigurableEnvironment environment, StringSE[] args) このアプリケーションの環境で PropertySource を追加、削除、並べ替えます。 |
protected org.springframework.context.ConfigurableApplicationContext | createApplicationContext() ApplicationContext の作成に使用される戦略方法。 |
protected org.springframework.boot.BeanDefinitionLoader | createBeanDefinitionLoader(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, ObjectSE[] sources) BeanDefinitionLoader の作成に使用されるファクトリメソッド。 |
static int | exit(org.springframework.context.ApplicationContext context, ExitCodeGenerator... exitCodeGenerators) SpringApplication を終了し、成功 (0) などを示すコードを取得するために使用できる静的ヘルパー。 |
SetSE<ObjectSE> | getAllSources() run(String...) が呼び出されたときに ApplicationContext に追加されるすべてのソースの不変のセットを返します。 |
protected org.apache.commons.logging.Log | getApplicationLog() アプリケーションの Log を返します。 |
ClassLoaderSE | getClassLoader() ApplicationContext で使用される ClassLoader( resourceLoader が設定されている場合、またはコンテキストクラスローダー(null でない場合)、または Spring ClassUtils クラスのローダーのいずれか。 |
SetSE<org.springframework.context.ApplicationContextInitializer<?>> | getInitializers() Spring ApplicationContext に適用される ApplicationContextInitializer の読み取り専用の順序付きセットを返します。 |
SetSE<org.springframework.context.ApplicationListener<?>> | getListeners() SpringApplication に適用され、 ApplicationContext に登録される ApplicationListener の読み取り専用の順序付きセットを返します。 |
ClassSE<?> | getMainApplicationClass() 推定または明示的に設定されたメインアプリケーションクラスを返します。 |
org.springframework.core.io.ResourceLoader | getResourceLoader() ApplicationContext で使用される ResourceLoader。 |
SetSE<StringSE> | getSources() run(String...) が呼び出されたときに ApplicationContext に追加されるソースの可変セットを返します。 |
WebApplicationType | getWebApplicationType() 実行中の Web アプリケーションの型を返します。 |
protected void | load(org.springframework.context.ApplicationContext context, ObjectSE[] sources) Bean をアプリケーションコンテキストにロードします。 |
protected void | logStartupInfo(boolean isRoot) 起動情報を記録するために呼び出され、サブクラスはオーバーライドして追加のログを追加できます。 |
protected void | logStartupProfileInfo(org.springframework.context.ConfigurableApplicationContext context) アクティブなプロファイル情報を記録するために呼び出されます。 |
static void | main(StringSE[] args) アプリケーションを起動するために使用できる基本的なメイン。 |
protected void | postProcessApplicationContext(org.springframework.context.ConfigurableApplicationContext context) ApplicationContext の関連する後処理を適用します。 |
protected void | refresh(org.springframework.context.ApplicationContext applicationContext) 基になる ApplicationContext をリフレッシュします。 |
protected void | registerLoggedException(ThrowableSE exception) 指定された例外が記録されたことを登録します。 |
static org.springframework.context.ConfigurableApplicationContext | run(ClassSE<?>[] primarySources, StringSE[] args) デフォルト設定とユーザー指定の引数を使用して、指定されたソースから SpringApplication を実行するために使用できる静的ヘルパー。 |
static org.springframework.context.ConfigurableApplicationContext | run(ClassSE<?> primarySource, StringSE... args) デフォルト設定を使用して、指定されたソースから SpringApplication を実行するために使用できる静的ヘルパー。 |
org.springframework.context.ConfigurableApplicationContext | run(StringSE... args) Spring アプリケーションを実行し、新しい ApplicationContext を作成およびリフレッシュします。 |
void | setAddCommandLineProperties(boolean addCommandLineProperties) 引数を公開するために、 CommandLinePropertySource をアプリケーションコンテキストに追加する必要があるかどうかを設定します。 |
void | setAddConversionService(boolean addConversionService) ApplicationConversionService をアプリケーションコンテキストの Environment に追加するかどうかを設定します。 |
void | setAdditionalProfiles(StringSE... profiles) 使用する追加のプロファイル値を設定します(システムまたはコマンドラインプロパティで設定された値の上に)。 |
void | setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding) 既存の定義と同じ名前の定義を登録することにより、Bean 定義のオーバーライドを許可するかどうかを設定します。 |
void | setApplicationContextClass(ClassSE<? extends org.springframework.context.ConfigurableApplicationContext> applicationContextClass) 作成される Spring ApplicationContext の型を設定します。 |
void | setBanner(Banner banner) 静的バナーファイルが提供されない場合にバナーを出力するために使用される Banner インスタンスを設定します。 |
void | setBannerMode(Banner.Mode bannerMode) アプリケーションの実行時にバナーを表示するために使用されるモードを設定します。 |
void | setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator) Bean 名を生成するときに使用する Bean 名ジェネレーターを設定します。 |
void | setDefaultProperties(MapSE<StringSE, ObjectSE> defaultProperties) 既存の Environment のプロパティに加えて使用されるデフォルトの環境プロパティを設定します。 |
void | setDefaultProperties(PropertiesSE defaultProperties) setDefaultProperties(Map) の便利な代替。 |
void | setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment) 作成されたアプリケーションコンテキストで使用される基本的な環境を設定します。 |
void | setHeadless(boolean headless) アプリケーションがヘッドレスであり、AWT をインスタンス化しないかどうかを設定します。 |
void | setInitializers(CollectionSE<? extends org.springframework.context.ApplicationContextInitializer<?>> initializers) Spring ApplicationContext に適用される ApplicationContextInitializer を設定します。 |
void | setListeners(CollectionSE<? extends org.springframework.context.ApplicationListener<?>> listeners) SpringApplication に適用され、 ApplicationContext に登録される ApplicationListener を設定します。 |
void | setLogStartupInfo(boolean logStartupInfo) アプリケーションの起動時にアプリケーション情報を記録するかどうかを設定します。 |
void | setMainApplicationClass(ClassSE<?> mainApplicationClass) ログソースとして使用され、バージョン情報を取得する特定のメインアプリケーションクラスを設定します。 |
void | setRegisterShutdownHook(boolean registerShutdownHook) 作成された ApplicationContext にシャットダウンフックを登録する必要があるかどうかを設定します。 |
void | setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader) リソースをロードするときに使用される ResourceLoader を設定します。 |
void | setSources(SetSE<StringSE> sources) ApplicationContext の作成に使用される追加ソースを設定します。 |
void | setWebApplicationType(WebApplicationType webApplicationType) 実行する Web アプリケーションの型を設定します。 |
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public static final StringSE DEFAULT_CONTEXT_CLASS
public static final StringSE DEFAULT_SERVLET_WEB_CONTEXT_CLASS
public static final StringSE DEFAULT_REACTIVE_WEB_CONTEXT_CLASS
public static final StringSE BANNER_LOCATION_PROPERTY_VALUE
public SpringApplication(ClassSE<?>... primarySources)
SpringApplication
インスタンスを作成します。アプリケーションコンテキストは、指定されたプライマリソースから Bean をロードします(詳細については、class-level
のドキュメントを参照してください。インスタンスは、run(String...)
を呼び出す前にカスタマイズできます。primarySources
- プライマリ Bean ソース run(Class, String[])
, SpringApplication(ResourceLoader, Class...)
, setSources(Set)
public SpringApplication(org.springframework.core.io.ResourceLoader resourceLoader, ClassSE<?>... primarySources)
SpringApplication
インスタンスを作成します。アプリケーションコンテキストは、指定されたプライマリソースから Bean をロードします(詳細については、class-level
のドキュメントを参照してください。インスタンスは、run(String...)
を呼び出す前にカスタマイズできます。resourceLoader
- 使用するリソースローダー primarySources
- プライマリ Bean ソース run(Class, String[])
, setSources(Set)
public org.springframework.context.ConfigurableApplicationContext run(StringSE... args)
ApplicationContext
を作成およびリフレッシュします。args
- アプリケーションの引数 (通常、Java メインメソッドから渡されます)ApplicationContext
protected void configureEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, StringSE[] args)
configurePropertySources(ConfigurableEnvironment, String[])
および configureProfiles(ConfigurableEnvironment, String[])
にこの順序で委譲するテンプレートメソッド。環境のカスタマイズを完全に制御するにはこのメソッドをオーバーライドします。プロパティソースまたはプロファイルを詳細に制御するには、上記のいずれかをそれぞれオーバーライドします。environment
- このアプリケーションの環境 args
- run
メソッドに渡される引数 configureProfiles(ConfigurableEnvironment, String[])
, configurePropertySources(ConfigurableEnvironment, String[])
protected void configurePropertySources(org.springframework.core.env.ConfigurableEnvironment environment, StringSE[] args)
PropertySource
を追加、削除、並べ替えます。environment
- このアプリケーションの環境 args
- run
メソッドに渡される引数 configureEnvironment(ConfigurableEnvironment, String[])
protected void configureProfiles(org.springframework.core.env.ConfigurableEnvironment environment, StringSE[] args)
spring.profiles.active
プロパティを使用して、構成ファイルの処理中に追加のプロファイルをアクティブ化できます。environment
- このアプリケーションの環境 args
- run
メソッドに渡される引数 configureEnvironment(ConfigurableEnvironment, String[])
, ConfigFileApplicationListener
protected void bindToSpringApplication(org.springframework.core.env.ConfigurableEnvironment environment)
SpringApplication
にバインドします。environment
- バインドする環境 protected org.springframework.context.ConfigurableApplicationContext createApplicationContext()
ApplicationContext
の作成に使用される戦略方法。デフォルトでは、このメソッドは、適切にデフォルトにフォールバックする前に、明示的に設定されたアプリケーションコンテキストまたはアプリケーションコンテキストクラスを考慮します。setApplicationContextClass(Class)
protected void postProcessApplicationContext(org.springframework.context.ConfigurableApplicationContext context)
ApplicationContext
の関連する後処理を適用します。サブクラスは、必要に応じて追加の処理を適用できます。context
- アプリケーションコンテキスト protected void applyInitializers(org.springframework.context.ConfigurableApplicationContext context)
ApplicationContextInitializer
をコンテキストに適用します。context
- 設定された ApplicationContext (まだリフレッシュされていません)ConfigurableApplicationContext.refresh()
protected void logStartupInfo(boolean isRoot)
isRoot
- このアプリケーションがコンテキスト階層のルートである場合は trueprotected void logStartupProfileInfo(org.springframework.context.ConfigurableApplicationContext context)
context
- アプリケーションコンテキスト protected org.apache.commons.logging.Log getApplicationLog()
Log
を返します。デフォルトでは推定されます。protected void load(org.springframework.context.ApplicationContext context, ObjectSE[] sources)
context
- Bean をロードするコンテキスト sources
- ロードするソース public org.springframework.core.io.ResourceLoader getResourceLoader()
public ClassLoaderSE getClassLoader()
resourceLoader
が設定されている場合、またはコンテキストクラスローダー(null でない場合)、または Spring ClassUtils
クラスのローダーのいずれか。protected org.springframework.boot.BeanDefinitionLoader createBeanDefinitionLoader(org.springframework.beans.factory.support.BeanDefinitionRegistry registry, ObjectSE[] sources)
BeanDefinitionLoader
の作成に使用されるファクトリメソッド。registry
- Bean 定義レジストリ sources
- ロードするソース BeanDefinitionLoader
protected void refresh(org.springframework.context.ApplicationContext applicationContext)
ApplicationContext
をリフレッシュします。applicationContext
- リフレッシュするアプリケーションコンテキスト protected void afterRefresh(org.springframework.context.ConfigurableApplicationContext context, ApplicationArguments args)
context
- アプリケーションコンテキスト args
- アプリケーションの引数 protected void registerLoggedException(ThrowableSE exception)
exception
- ログに記録された例外 public ClassSE<?> getMainApplicationClass()
null
public void setMainApplicationClass(ClassSE<?> mainApplicationClass)
null
に設定できます。mainApplicationClass
- mainApplicationClass を設定するか null
を設定する public WebApplicationType getWebApplicationType()
public void setWebApplicationType(WebApplicationType webApplicationType)
webApplicationType
- Web アプリケーションの種類 public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
false
です。allowBeanDefinitionOverriding
- オーバーライドが許可されている場合 DefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean)
public void setHeadless(boolean headless)
true
になります。headless
- アプリケーションがヘッドレスの場合 public void setRegisterShutdownHook(boolean registerShutdownHook)
ApplicationContext
にシャットダウンフックを登録する必要があるかどうかを設定します。JVM のシャットダウンが正常に処理されるようにするため、デフォルトは true
です。registerShutdownHook
- シャットダウンフックを登録する必要がある場合 public void setBanner(Banner banner)
Banner
インスタンスを設定します。banner
- 使用する Banner インスタンス public void setBannerMode(Banner.Mode bannerMode)
Banner.Mode.CONSOLE
です。bannerMode
- バナーの表示に使用されるモード public void setLogStartupInfo(boolean logStartupInfo)
true
です。logStartupInfo
- 起動情報を記録する必要がある場合。public void setAddCommandLineProperties(boolean addCommandLineProperties)
CommandLinePropertySource
をアプリケーションコンテキストに追加する必要があるかどうかを設定します。デフォルトは true
です。addCommandLineProperties
- コマンドライン引数を公開する必要がある場合 public void setAddConversionService(boolean addConversionService)
ApplicationConversionService
をアプリケーションコンテキストの Environment
に追加するかどうかを設定します。addConversionService
- アプリケーション変換サービスを追加する必要がある場合 public void setDefaultProperties(MapSE<StringSE,ObjectSE> defaultProperties)
Environment
のプロパティに加えて使用されるデフォルトの環境プロパティを設定します。defaultProperties
- 設定する追加のプロパティ public void setDefaultProperties(PropertiesSE defaultProperties)
setDefaultProperties(Map)
の便利な代替。defaultProperties
- いくつかの Properties
SEpublic void setAdditionalProfiles(StringSE... profiles)
profiles
- 設定する追加のプロファイル public void setBeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator beanNameGenerator)
beanNameGenerator
- Bean 名前ジェネレーター public void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment)
environment
- 環境 public void addPrimarySources(CollectionSE<ClassSE<?>> additionalPrimarySources)
run(String...)
が呼び出されたときに ApplicationContext に追加されるプライマリソースに追加のアイテムを追加します。 ここでのソースは、コンストラクターで設定されたソースに追加されます。ほとんどのユーザーは、このメソッドを呼び出すのではなく、getSources()
/setSources(Set)
の使用を検討する必要があります。
additionalPrimarySources
- 追加する追加のプライマリソース SpringApplication(Class...)
, getSources()
, setSources(Set)
, getAllSources()
public SetSE<StringSE> getSources()
run(String...)
が呼び出されたときに ApplicationContext に追加されるソースの可変セットを返します。ここで設定されたソースは、コンストラクターで設定されたプライマリソースに加えて使用されます。
SpringApplication(Class...)
, getAllSources()
public void setSources(SetSE<StringSE> sources)
ここで設定されたソースは、コンストラクターで設定されたプライマリソースに加えて使用されます。
sources
- 設定するアプリケーションソース SpringApplication(Class...)
, getAllSources()
public SetSE<ObjectSE> getAllSources()
run(String...)
が呼び出されたときに ApplicationContext に追加されるすべてのソースの不変のセットを返します。このメソッドは、コンストラクターで指定された主なソースを、explicitly set
である追加のソースと組み合わせます。public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
ResourceLoader
を設定します。resourceLoader
- リソースローダー public void setApplicationContextClass(ClassSE<? extends org.springframework.context.ConfigurableApplicationContext> applicationContextClass)
ApplicationContext
の型を設定します。指定しない場合、Web ベースのアプリケーションでは DEFAULT_SERVLET_WEB_CONTEXT_CLASS
に、Web 以外のアプリケーションでは AnnotationConfigApplicationContext
にデフォルト設定されます。applicationContextClass
- 設定するコンテキストクラス public void setInitializers(CollectionSE<? extends org.springframework.context.ApplicationContextInitializer<?>> initializers)
ApplicationContext
に適用される ApplicationContextInitializer
を設定します。initializers
- 設定する初期化子 public void addInitializers(org.springframework.context.ApplicationContextInitializer<?>... initializers)
ApplicationContext
に適用される ApplicationContextInitializer
を追加します。initializers
- 追加する初期化子 public SetSE<org.springframework.context.ApplicationContextInitializer<?>> getInitializers()
ApplicationContext
に適用される ApplicationContextInitializer
の読み取り専用の順序付きセットを返します。public void setListeners(CollectionSE<? extends org.springframework.context.ApplicationListener<?>> listeners)
ApplicationContext
に登録される ApplicationListener
を設定します。listeners
- 設定するリスナー public void addListeners(org.springframework.context.ApplicationListener<?>... listeners)
ApplicationListener
を追加して SpringApplication に適用し、ApplicationContext
に登録します。listeners
- 追加するリスナー public SetSE<org.springframework.context.ApplicationListener<?>> getListeners()
ApplicationContext
に登録される ApplicationListener
の読み取り専用の順序付きセットを返します。public static org.springframework.context.ConfigurableApplicationContext run(ClassSE<?> primarySource, StringSE... args)
SpringApplication
を実行するために使用できる静的ヘルパー。primarySource
- ロードする主なソース args
- アプリケーションの引数 (通常、Java メインメソッドから渡されます)ApplicationContext
public static org.springframework.context.ConfigurableApplicationContext run(ClassSE<?>[] primarySources, StringSE[] args)
SpringApplication
を実行するために使用できる静的ヘルパー。primarySources
- ロードする主なソース args
- アプリケーションの引数 (通常、Java メインメソッドから渡されます)ApplicationContext
public static void main(StringSE[] args) throws ExceptionSE
ほとんどの開発者は、独自のメインメソッドを定義し、代わりに run
メソッドを呼び出します。
args
- コマンドライン引数 ExceptionSE
- アプリケーションを開始できない場合 run(Class[], String[])
, run(Class, String...)
public static int exit(org.springframework.context.ApplicationContext context, ExitCodeGenerator... exitCodeGenerators)
SpringApplication
を終了し、成功 (0) などを示すコードを取得するために使用できる静的ヘルパー。例外をスローしませんが、発生したスタックトレースを出力する必要があります。ExitCodeGenerator
を実装する Spring Bean に加えて、指定された ExitCodeGenerator
を適用します。複数の終了コードの場合、最高値が使用されます (または、すべての値が負の場合、最も低い値が使用されます)context
- 可能な場合に閉じるコンテキスト exitCodeGenerators
- 存在するコードジェネレーター Copyright © 2019 Pivotal Software, Inc.. All rights reserved.