美文网首页
Spring---IOC和DI

Spring---IOC和DI

作者: 大树懒呵 | 来源:发表于2018-10-04 14:13 被阅读0次

    application context

    1.AnnotationConfigApplicationContext
    2.AnnotationConfigWebApplicationContext
    3.ClassPathXmlApplicationContext
    4.FileSystemXmlApplicationContext
    5.XmlWebApplicationContext
    

    Wiring beans

    1.Explicit configuration in XML
    2.Explicit configuration in Java
    3.Implicit bean discovery and automatic wiring 
    

    Automatically wiring beans [Implicit]

    1.Component scanning---Spring automatically disvocers beans to be created in application context

    2.Autowiring ---Spring automatically satisfies beans bean dependencies

    Component scanning

    1.discoverable beans ------@Component ....
    2.Scanning -----@ComponentScan. Default Scanning that(which class have @ComponentScan)package and any subpackage.
            explicit way -> basePackages={packageName,..} or basePackageClasses={xx.class,yy.class}
    

    Annotating beans to be automatically wired

    Autowiring is a means of letting Spring automatically satisfy a bean's dependencies by finding other beans in application context are a match to the bean's needs.

    @Autowired --- you can use in a constructor,a setter method,or any other method,Spring will attempt to satisfy the dependency expressed in the method's parameters.

    In java and In Xml [explicit]

    Importing and mixing configurations

    In java

    1.@Import("xxx.class")
    2.@ImportResource("classpath:xxx.xml")

    In Xml

    1.<Import resource="xxx.xml" >
    2.<Import class="xxxx.config" >

    相关文章

      网友评论

          本文标题:Spring---IOC和DI

          本文链接:https://www.haomeiwen.com/subject/pnexaftx.html