Spring Annotations development --------> @Configuration notes (a)

The key is to add a class javaConfig @Configuration comment.

@Configuration annotation indicates that this class is a class configuration. Components can initiate a scan for the entity with @Bean instantiate the like bean

       @Configuration understood as a spring when the inside xml <beans> tag, which is: disposed spring containers (application context)

       @Bean understood as a spring when the inside xml <bean> tag

@ComponentScan(value="com.xxx",excluddFilters={@Filter(type=FilterType.ANNOTATION,classes={Controller.class,Service.class})})

@ComponentScan(value="com.xxx",includeFilters={@Filter(type=FilterType.ANNOTATION,classes={Controller.class},userDefaultFilters=false)})

// value: scan the specified package

// excluddFilters = the Filter [] Specifies exclude those components 

// includeFilters = the Filter [] // Specify those containing components to scan, scan only if the configuration includes rules, the same time to configure userDefault-filters = false; disable the default filtering rules;

Filter Type:

 

 

@Configuration // == configuration class configuration file, the comment was repeated notes, you can live a comment

@ComponentScan // Enable component scans

public   class   CDPlayerConfig{

      CdPlayer @Bean // instantiate an object placed in the vessel. Registered a bean, id defaults to the method name

     public    CDPlayer   cdPlayer(){

           return  new CDPlayer();

    }

}

 

Note : @Configuration annotation configuration class has the following requirements:

  1. @Configuration may not be the final type;
  2. @Configuration is not anonymous class;
  3. Nested configuration must be static class.

Guess you like

Origin blog.csdn.net/m0_37668842/article/details/82707892