インタビュアーの子供が無知である、それは私が春@Configurationに理解していないためであることが判明しました

春の注釈のインタビューでは、あなたが尋ねた致命的な連鎖インタビュアーの期間が発生することがあります。

(1)@Configuration使用することは何ですか?

(2)@ConfigurationとXMLの違いは何ですか?どちらが良いですか?

(3)春は、Beanの定義を取得する方法に基づいていますか?初期豆を遅らせる方法?

(4)@Autowired、注入する、@、@リソースの違いは何ですか?

(5)値@、PropertySource和@Configuration @?

(6)の@Configuration @importで春のクラスをどのように扱いますか?

(7)@Profile使用することは何ですか?

どのように(8)@Configurationの巣?

どのように(9)春のプロジェクトのユニットテスト?

@Configurationの使用に関する(10)が持っている制約は何ですか?

基本命令@Configuration

**定義:Beanクラスの定義と実行時にサービス要求Beanを生成するように、クラス宣言は、1つまたは複数のメソッドと@Bean統合管理Springコンテナを指定します示しています。**例:

@ConfigurationpublicclassAppConfig {@BeanpublicMyBeanmyBean(){returnnewMyBean()。}}

AppConfigの上に、これはコンフィギュレーション・クラスであることを、@Configurationノートに参加。MyBeanと(​​)メソッドは、インスタンスの)(ザMyBeanとを返し、@Beanで注釈は、この方法は、豆スプリング管理する必要があることを示しています。名前を指定しない場合@Bean、その後、小文字の名前であり、デフォルトのMyBeanと名前を使用します。

1.ノート

次のようなこの@Configuration注釈付きクラスを、案内するAnnotationConfigApplicationContextを開始することにより

AnnotationConfigApplicationContext CTX = newAnnotationConfigApplicationContext(); ctx.register(AppConfig.class); ctx.refresh()。

Webプロジェクトでは、あなたも開始するAnnotationContextWebApplicationContextまたは他の変異体を使用することができます。

新しいプロジェクトを(なぜプロジェクトを作成するために高速であるため、私に聞かないでください)SpringBoot。

(1)のpom.xml以下のドキュメント

<?xml version = "1.0" エンコード= "UTF-8"?> 4.0.0org.springframework.bootspringブート・スタータparent2.1.5.RELEASE <! - リポジトリからのルックアップの親 - > com.spring.configurationspring春Boot1.8org.springframework.bootspringブート・スターター・testtestorg.springframeworkspring-context5.0.6.RELEASEorg.springframework.bootspring-ブートのmaven-pluginのため-configuration0.0.1-SNAPSHOTspring-configurationDemoプロジェクト

新しい設定でパケットMyConfigurationを次のように環境設定、および上記のサンプルコードと同様に、完全なコードは次のようになります。

@ConfigurationpublicclassMyConfiguration {@BeanpublicMyBeanmyBean(){System.out.printlnは( "MyBeanと初期化"); returnnewMyBean()。}}

説明MyConfigurationは、我々はそれがロードされ、コンテナ管理することにしたい、豆のMyBeanとを宣言し、複数のビーン以下、このような文を管理することが可能な構成クラス、です。

新しいパッケージPOJOでMyBeanと、次のようにクラス固有のコード

publicclassMyBean {publicMyBean(){System.out.printlnは( "生成MyBeanとインスタンス")。} publicvoidinit(){System.out.printlnは( "MyBeanとリソース初期化")。}}

作成SpringConfigurationApplicationの次のようにテストMyConfigurationクラス固有のコードのクラスを:

publicclassSpringConfigurationApplication {publicstaticvoidmain(文字列[] args)を{// AnnotationConfigApplicationContextコンテキスト= =新しいAnnotationConfigApplicationContext(MyConfiguration.class)//私たちは、あなたがAnnotationConfigApplicationContextAnnotationConfigApplicationContextコンテキスト= newAnnotationConfigApplicationContext()を作成する必要がありますので@Configurationは、ノートの形に基づいてロードされているので; //レジスタMyConfigurationクラスとBeanコンテナを更新します。context.register(MyConfiguration.class); context.refresh();}}

(2)出力

MyBeanと初期化

MyBeanとインスタンスを生成します

ので、結果出力から見ることができ、Beanコンテナにロードされたデフォルトの名前は、MyBeanとロードされるMyBeanと MyBeanとが初期化されて方法は、コンストラクタMyBeanとを返します。

XMLを介して2.スタート

<コンテキスト:アノテーション設定/> XMLの実施形態を使用して定義することができるオープン・ベースのアノテーションを開始し、その後、豆のMyConfigurationを定義し、/リソースディレクトリ次のように新しいアプリケーションのcontext.xmlコードです。

<?xml version = "1.0" エンコード= "UTF-8"?>

      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd"><!--、同等のアノテーションベースの起動クラスAnnotationConfigApplicationContext-- >

applicationContext.xmlをを導入する必要があり、我々は次のようにSpringConfigurationApplication、SpringConfigurationApplicationを組み込む修正する必要があります。

publicclassSpringConfigurationApplication {publicstaticvoidmain(文字列[]引数){ApplicationContextのコンテキスト= newClassPathXmlApplicationContext( "applicationContext.xmlを")。}}

出力:

MyBeanと初期化

MyBeanとインスタンスを生成します

ビーンの定義を手に入れるためにComponentScanを()ベースの

使用@Componentため@Configuration元のアノテーションは、このよう@Configurationクラスは、(特定のXMLの使用アセンブリに走査することができる:部品Scan-コンテキスト要素)。

:ここではいくつかの注意事項を知って@Controller、@Service、@Repository、@Componentを

@Controller:注釈クラスが、それはこの役割のコントローラMVCパターンとして理解することができるコントローラである「コントローラ」、であることを示しています。これは、走査型クラスパスでスキャンすることができます、特別な注釈@Componentです。これは通常@RequestMappingコメントと併せて使用されています。

@Service:注釈付きのクラスは、サービス層である「サービス」であり、それはMVCモードサービスレベルとしての役割を理解することができることを示し、この注釈は、クラスパスを介して実装クラスを可能にする、特別@Componentありますスキャンするスキャン

@Repository:PersistenceExceptionTranslationPostProcessorと組み合わせて使用​​すると、注釈付きクラスは変換春の対象となり、「データアクセスオブジェクト」としてDAOとして使用することができるように注釈付きクラスが「リポジトリ」であることを示し、チームはJavaEEのモードを実現目的。この注釈は、クラスが自動的にスキャンされることを可能にする、特定の実装を@Componentれます

@Component:注釈は、クラスを使用アノテーションベースの設定とパス走査クラスは、これらのクラスは、自動検出のための候補と考えられる成分であることを示しています。

言い換えれば、シーンと意味注釈の最大の違いをスキャンすることができるように@ComponentScanでマークされたノートの上の4つのクラスは、上記の4つの使用は、あなたがしなければならない、例えば、あなたが春を管理するために、クラス・サービスの定義になりたい、同じではありませんされて我々は意味的に、@のサービスは、より一般的にコンポーネントと呼ばサービスではなく、クラスのコントローラ、@コンポーネントと同様であるので、それは@Service代わり@Controllerクラスとして定義され、それはあなたが任意の厳格を持っていないマークを付けることができます例えば、コンフィギュレーション・クラスである、それはMVCパターンのいずれかの層に属していない、と指摘するクラスは、この時間は、あなたは@Componentとしてそれを定義する方が慣れています。これら三つのノートが@Componentと交換することができるので、@Componentを持っている上のリポジトリ注釈@サービス@ @コントローラー、、。

理解するためのコードを見てください:

次のようにそれぞれ@Controller、@Service、@Repository、@Component、@Configurationタギングに基づいて5つのクラスを定義し、あります

@ComponentpublicclassUserBean {} ConfigurationpublicclassUserConfiguration @ {} ControllerpublicclassUserController @ {} RepositorypublicclassUserDao @ {} ServicepublicclassUserService @ {}复制代码

MyConfigurationで、パッケージ上位5つのクラスの走査位置を注釈を追加すること@ComponentScan。コードは以下の通りであります:

@設定@ ComponentScan(basePackages = "com.spring.configuration.pojo")publicclassMyConfiguration {@BeanpublicMyBeanmyBean(){System.out.printlnは( "MyBeanと初期化"); returnnewMyBean()。}}复制代码

次のようにSpringConfigurationApplicationは、コードを変更します。

publicclassSpringConfigurationApplication {publicstaticvoidmain(文字列[]引数){// AnnotationConfigApplicationContextコンテキスト= =新しいAnnotationConfigApplicationContext(MyConfiguration.class)//のApplicationContextコンテキスト=新しいClassPathXmlApplicationContext( "applicationContext.xmlを"); AnnotationConfigApplicationContextコンテキスト= newAnnotationConfigApplicationContext()。context.register(MyConfiguration.class)。context.refresh(); //获取启动过程中的ビーン定义的名称(文字列str:context.getBeanDefinitionNames()){ためのSystem.out.println( "STR =" + STR)。} context.close()。}}复制代码

出力:

MyBeanと初期化

MyBeanとインスタンスを生成します

STR = org.springframework.context.annotation.internalConfigurationAnnotationProcessor

STR = org.springframework.context.annotation.internalAutowiredAnnotationProcessor

STR = org.springframework.context.annotation.internalRequiredAnnotationProcessor

STR = org.springframework.context.annotation.internalCommonAnnotationProcessor

STR = org.springframework.context.event.internalEventListenerProcessor

STR = org.springframework.context.event.internalEventListenerFactory

STR = myConfiguration

STR = UserBeanの

STR = userConfiguration

STR = UserControllerで

STR = userDao

STR = UserServiceの

STR = MyBeanと

はっきり出力から見ることができ、上記で定義された5つのクラスが正常にスキャン@ComponentScan、およびプログラムの起動時にロードされています。

3. @Configuration和環境

通常、@Configuration環境で使用@Environment性質によって解決されたオブジェクト1つ以上の「ソースの属性」に常駐し、@の設定クラスは@PropertySourceを使用することができる、オブジェクトなどのプロパティは、ソース環境を提供しています

テストを容易にするために、我々は完全なプロファイル以下、junit4と春試験の導入に依存しています

<?xml version = "1.0" エンコード= "UTF-8"?> 4.0.0org.springframework.bootspringブート・スタータparent2.1.5.RELEASE <! - リポジトリからのルックアップの親 - > com.spring.configurationspringスプリングBoot1.85.0.6.RELEASE4.3.13.RELEASE4.12org.springframework.bootspringブート・スタータtesttestorg.springframeworkspringコンテキスト$ {spring.version}の-configuration0.0.1-SNAPSHOTspring-configurationDemoプロジェクトorg.springframeworkspringテスト$ {spring.test.version} junitjunitの$ {junit.version} org.springframework.bootspring-ブートのmaven-プラグインを复制代码

次のように設定EnvironmentConfigクラス注入環境プロパティで定義されたパケットは、完全なコードです。

@TestpublicvoidtestReadProperty(){// bean.name.controllerのプロパティを取得します。publicclassEnvironmentConfig {@AutowiredEnvironment ENV:PropertySource( "beanName.propertiesクラスパス")@設定@ @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(クラス= EnvironmentConfig.class) System.out.println(env.getProperty( "bean.name.controller")); //はbean.name.componentSystem.out.println(env.containsProperty( "bean.name.component"))かどうかを決定することを含みます; / /バック指定された属性値のSystem.out.println(env.getRequiredProperty(「bean.name.service」))に関連付けられたキー;}}コードをコピー

/リソースディレクトリに新しいbeanName.propertiesファイル、次のように:

bean.name.configuration = beanNameConfigurationbean.name.controller = beanNameControllerbean.name.service = beanNameServicebean.name.component = beanNameComponentbean.name.repository = beanNameRepository复制代码

次のように起動して、JUnitテスト、出力は次のようになります。

... .. ... ...

beanNameController

beanNameService

... .. ... ...

のリソース@ジェクト@区別4. @Autowired、

@Inject:これはAutowiredAnnotationBeanPostProcessorクラス注射を頼ることによって達成さjsr330仕様です。パッケージ内に位置Javax.injectは、Javaの独自のアノテーションです。

@名前(「環境」)環境ENV @注入します。

コメントなし@Named、あなたがすることができ、同じ変数名を設定する必要があります。

@Autowired:@Autowired春の注釈はAutowiredAnnotationBeanPostProessorクラスを注入することによって実現、提供されます。内にあるOrg.springframework.beans.factory.annotationパッケージには、春の注釈であります

@AutowiredEnvironment ENV;

デフォルトはbyTypeを注入することにより達成され、

@Resource:@Resource jsr250仕様は、@リソースクラスCommonAnnotationBeanPostProcessorは、注射によって達成、実現されています。次のように@Resourceは、一般的に、name属性を指定します。

@Resource(名前=「環境」)環境ENV、重複したコード

デフォルトはBYNAMEを注入することにより達成され、

違い:

両方がAutowiredAnnotationBeanPostProcessor依存性注入を処理するために使用されているので、@Autowiredと@Inject実質的に同じ。@Resourceしかし例外で、CommonAnnotationBeanPostProcessorの依存性注入を処理するために使用されます。もちろん、両方BeanPostProcessor。

上記3つの差に導入した後、環境属性は、上記のように噴射で修飾することができます

PropertySource和@Configuration @値、

@Configurationが@PropertySource @value一緒に使用され、外部のプロファイルを読み出すことができる以下のように、使用されています。

次のように、設定パケットに新しいクラスをReadValueFromPropertySource

@PropertySource:ConfigurationpublicclassReadValueFromPropertySource {@value( "bean.name.component")文字列のbeanName @( "クラスパスbeanName.properties"); @Bean( "myTestBean")publicMyBeanmyBean(){returnnewMyBean(のbeanName)。}}

MyBeanと(​​)メソッドでは、属性値を取得することができる@valueによって導入されたプロファイル@PropertySourceするmyTestBean呼ばれる名前を指定します。

name属性と、toString()メソッドを再生コンストラクタを追加MyBeanとクラスの修飾、

publicclassMyBean {文字列名; publicMyBean(文字列名){this.name =名。} publicMyBean(){System.out.printlnは( "MyBeanとインスタンスを生成します")。} publicvoidinit(){System.out.printlnは( "MyBeanとリソース初期化")。} @OverridepublicStringtoString(){リターン "MyBeanと{" + "NAME = '" +名+ '\' '+'}'。}}

次のようにSpringConfigurationApplicationは、試験されました

publicclassSpringConfigurationApplication {publicstaticvoidmain(文字列[] args)を{//コードが削除されていない前に、設定ファイルの整合性を証明するために。// AnnotationConfigApplicationContextコンテキスト= =新しいAnnotationConfigApplicationContext(MyConfiguration.class)//のApplicationContextコンテキスト=新しいClassPathXmlApplicationContext( "applicationContext.xmlを"); // AnnotationConfigApplicationContextコンテキスト=新しいAnnotationConfigApplicationContext(); // context.register(MyConfiguration.class); / / context.refresh(); //// //のBean定義起動処理//の名前取得(文字列str:context.getBeanDefinitionNamesを()){//するSystem.out.println( "STR =" + STR ); //} // context.close(); ApplicationContextのコンテキスト= newAnnotationConfigApplicationContext(ReadValueFromPropertySource.class); MyBeanとMyBeanと=(MyBeanと)context.getBean( "

アプリケーションシート@ InConntextがmyTestBean Beanを取得した後、MyBeanとのインスタンスを生成することができます使用してください。

输出:MyBeanと= MyBeanと{NAME = 'bean.name.component'}

5. @import和@Configuration

@importは(のJavaDocから)に定義される:一つ以上のニーズが設定クラスをインポートすることを示し、スプリングXMLインポート@Configuration、@ ImportSelector、@ ImportBeanDefinitionRegistar達成、及び同様の従来の成分AnnotationConfigApplicationContextを可能にする、同等の機能を提供します。クラスレベルまたは元のコメントのために可能。XMLまたは他の非@設定マークを必要と豆のリソースをインポートする場合は、@ImportResourceを使用しています。以下はサンプルコードです:

二つの新しいクラスのPOJO構成パッケージ、すなわちCustomerBo、SchedualBoで

@ConfigurationpublicclassCustomerBo {publicvoidprintMsg(文字列MSG){するSystem.out.println( "CustomerBo:" + MSG)。} @BeanpublicCustomerBotestCustomerBo(){returnnewCustomerBo()。}} ConfigurationpublicclassSchedulerBo {publicvoidprintMsg(文字列MSG){@するSystem.out.println( "SchedulerBo:" + MSG)。} @BeanpublicSchedulerBotestSchedulerBo(){returnnewSchedulerBo()。}}复制代码

AppConfigはCustomerBoとSchedulerBoを導入設定で新しいパッケージを作成します。

インポート(値= {CustomerBo.class、SchedulerBo.class})publicclassAppConfig {} @構成

新しいImportWithConfigurationの設定パッケージには、テスト@importと@Configurationでの使用のために

publicclassImportWithConfiguration {publicstaticvoidmain(文字列[]引数){ApplicationContextのコンテキスト= newAnnotationConfigApplicationContext(AppConfig.class)。CustomerBo customerBo =(CustomerBo)context.getBean( "testCustomerBo")。customerBo.printMsg( "システムのうちのprintln( 'customerBoから取得')"); SchedulerBo schedulerBo =(SchedulerBo)context.getBean( "testSchedulerBo")。schedulerBo.printMsg( "システムのうちのprintln( 'schedulerBoから取得')"); }}

出力:

CustomerBo:システムアウトのprintln( 'customerBoから取得')

SchedulerBo:システムアウトのprintln( 'schedulerBoから取得')

@プロフィール

@Profile:指定@valueプロファイルの1つ以上が使用可能である場合、コンポーネントは、登録条件が登録されていてもよい満たす示します。

次の3つの方法のセット:

()ConfigurableEnvironment.setActiveProfilesによってプログラム的に起動することができます

AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME(spring.profiles.active)のプロパティにより、

JVMプロパティ

環境変数として、またはサーブレットweb.xmlのアプリケーションコンテキストパラメータとして。また@ActiveProfilesは、設定ファイルの統合テストで宣言コメントをアクティブにすることができます。

スコープ

クラスレベルのアノテーションとして、または直接いかなるタイプ@Component関連するクラスの@Configurationを含みます

オリジナルのノートとして、注釈をカスタマイズすることができます

いずれかの方法で、アノテーションの役割の方法として、

注意

プロファイルクラスラベルまたは@Profile役割を使用してプロファイルが@Profile({「P1」、「!P2が」})の2つの属性が識別された場合、任意のクラスに反映するために有効にする必要がある場合は、P1有効になっていますそして、p2の非有効状態。

6. @ImportResource和@Configuration

@ImportResource:このアノテーションは、多くの場合、@Configurationで使用@importの役割と同様の機能を提供し、使用方法の具体例を以下になり、AnnotationConfigApplicationContextによって開始されました。

設定の新しいTestServiceクラス、クラスが初期化されるときに呼び出されるコンストラクタを宣言する

publicclassTestService {publicTestService(){System.out.printlnは( "試験@importResource成功")。}}

新しいimportResources.xml / resourcesディレクトリには、TestServiceを導入するために

<?xml version = "1.0" エンコード= "UTF-8"?>

      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd

      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd「>コードをコピー

設定ファイルを読み込むための設定では、新しいImportResourceWithConfiguration、

@設定@ ImportResource( "クラスパス:importResources.xml")publicclassImportResourceWithConfiguration {@AutowiredprivateTestServiceサービス; publicvoidgetImportResource(){newTestService(); } publicstaticvoidmain(文字列[]引数){AnnotationConfigApplicationContextコンテキスト= newAnnotationConfigApplicationContext(ImportResourceWithConfiguration.class)。context.getBean( "testService"); }}

出力:テスト@importResource成功

7. @Configurationネストされました

@Configurationアノテーションはクラスに作用し、そしてお互いの中に入れ子にすることができるように一般的なクラスは、内部クラスを定義します。

@BeanpublicMyBeanmyBean(){returnnewMyBean(データソース); ConfigurationpublicclassAppConfig {@InjectDataSourceデータソース@ //来自のJavaDoc。{BeanDataSourcedataSource @(){returnnewEmbeddedDatabaseBuilder()。ビルド()}} @ConfigurationstaticclassDataConfig()}}

上記のコードでは、あなただけがアプリケーションのコンテキストでのAppConfigを登録する必要があります。クラスは@Configurationを入れ子になっているので、DatabaseConfigが自動的に登録されています。ときのAppConfig、DatabaseConfigとの関係は明らかに@import注釈を使用する必要性を回避する、暗示しています。

@Lazy遅延初期化

@Lazy:Beanが、この方法は、遅延ローディングを示している、方法で作用し得る、遅延ローディングかどうかを示す; @Componentは、このクラスは、すべての豆であることを示し、ベースの注釈(オリジナルまたは@Componentによって注釈される)に作用することができます遅延ロードされて。何もコメントがない場合@Lazyまたは@Lazyがfalseに設定され、その後、Beanは緊急の欲求をロードされます。上記の2つのスコープに加えて、レイジー@またここで、プロパティや@Inject @Autowired注釈に作用することができます場合、それはのObjectFactoryまたはプロバイダのデフォルト方法として、そのフィールドの不活性剤を生成します。さんがあなたをお見せしましょう:

クラスに@Lazyアノテーションを追加し、MyConfigurationクラスを変更し、初期化するかどうかをチェックするIfLazyInit()メソッドを追加します。

@レイジー@設定@ ComponentScan(basePackages = "com.spring.configuration.pojo")publicclassMyConfiguration {@BeanpublicMyBeanmyBean(){System.out.printlnは( "MyBeanと初期化"); returnnewMyBean()。} @BeanpublicMyBeanIfLazyInit(){System.out.printlnは( "初期化"); returnnewMyBean()。}}复制代码

あなたはSpringConfigurationApplication起動クラスを変更する前に、オープンMyConfigurationは、クラスを開始します

publicclassSpringConfigurationApplication {publicstaticvoidmain(文字列[]引数){AnnotationConfigApplicationContextコンテキスト= newAnnotationConfigApplicationContext(MyConfiguration.class); //のApplicationContextコンテキスト=新しいClassPathXmlApplicationContext( "applicationContext.xmlを"); // AnnotationConfigApplicationContextコンテキスト=新しいAnnotationConfigApplicationContext(); // context.register (MyConfiguration.class); // context.refresh(); //// //获取启动过程中的ビーン定义的名称ため(文字列str:context.getBeanDefinitionNames()){するSystem.out.println( "STR = 「+ STR); } // context.close(); //のApplicationContextコンテキスト= //新しいAnnotationConfigApplicationContext(ReadValueFromPropertySource.class); // MyBeanとMyBeanと=(MyBeanと)context.getBean( "myTestBean")。

あなたは豆についての定義の出力情報を見つけていないだろうが、それは削除コメントを@Lazyとき、あなたは、Beanの初期化の出力に関する情報が表示されます:

MyBeanと初期化

MyBeanとインスタンスを生成します

初期化

MyBeanとインスタンスを生成します

8. @RunWith和@ContextConfiguration

アノテーションがJunit4でテストを表すためにJunit4テストクラスは、書き込みのクラスコードが省略されて起動することができ、などが交換されたクラスで授業を開始するのApplicationContext。通常、ユニットテストとソフトウェア開発プロセスに不可欠であるとEnvironmentConfig上記プロ部分を持っている@RunWith @Configuration、のためにこのクラスが確認されます。

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(クラス= EnvironmentConfig.class)@設定@ PropertySource( "クラスパス:beanName.properties")publicclassEnvironmentConfig {// @ Autowired //環境ENV; @InjectEnvironmentのENV; @TestpublicvoidtestReadProperty(){/属性(env.getProperty( "bean.name.controllerを"))を取得する/するSystem.out.printlnのbean.name.controller; // bean.name.componentSystem.out.println(env.containsProperty(「ビーンか否かを決定することを含みます.name.component ")); //は、与えられたキー値のSystem.out.println(env.getRequiredProperty(関連付けられた属性を返し" bean.name.serviceを「));}}

9.春の組み込み機能を開始@Enable

詳細は、@ EnableAsync、@ EnableScheduling、@ EnableTransactionManagement、@ EnableAspectJAutoProxy、@ EnableWebMvc公式文書をチェック

10. @Configuration、使用上の制約

それは同様に提供されなければならない(すなわち、実施例は、ファクトリメソッドから返されていません)

@Configuration注釈付きクラスは非finalでなければなりません

Configurationクラスは、(つまり、メソッドが宣言されない場合があります)ネイティブ標識法非ローカルでなければなりません

任意のネストされた@Configurationは静的である必要があります。

@Bean方法は、順番に、追加の構成クラスを作成することはできません

おすすめ

転載: blog.csdn.net/mifffy_java/article/details/91948377