美文网首页
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

    application context Wiring beans Automatically wiring bea...

  • Spring---IOC/AOP

    IOC:控制反转/依赖注入;之前你要使用一个类,你需要用new实例化一个对象,然后使用,这用类与类之间的依赖太大你...

  • IoC和DI

    IOC和DI是Spring的核心功能之一,平时在使用的时候最直观的感觉就是用@Autowired代替了new,越是...

  • IOC和Di

  • SpringIOC和DI

    spring中依赖注入就是给属性赋值(java学到现在,通常给属性赋值有哪几种方式?最常用的是set方法和构造函数...

  • I Am You(我就是你)

    La di da di da da La di da di da da La di da di da da La ...

  • I am you

    La di da di da da La di da di da da La di da di da da La ...

  • I AM YOU

    La di da di la da La di da di la da La di da di la da La ...

  • kim taylor-《i am you》

    La di da di da da La di da di da da La di da di da da La ...

  • Spring IoC Container 原理解析

    IoC、DI基础概念 关于IoC和DI大家都不陌生,我们直接上martin fowler的原文,里面已经有DI的例...

网友评论

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

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