zoukankan      html  css  js  c++  java
  • Spring IOC

    Ioc(Inversion of control)控制反转。

    在Spring中我们将beans的创建交给了 Ioc容器。它将读取配置文件来创建beans实例。

    Spring提供了两种Ioc容器的实现:一种是通过bean工厂(Bean Factory),更高级的一种是bean工厂的扩展应用程序上下文(Application context)。

    bean工厂和应用程序上下文的两个接口分别是BeanFactory和ApplicationContext(是BeanFactory的子接口)。

    ApplicationContext的实现:

      ClassPathXmlApplicationContext:用于装载classpath下的配置文件。

      FileSystemXmlApplicationContext:用于从文件系统或URL装载配置文件。

      XmlWebApplicationContext和XmlPortletApplicationContext:用于从网络装载配置文件。

    如果只是简单的bean配置只需要声明如下头:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    </beans>

    使用简写定义bean属性,必须在头重声明:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:p="http://www.springframework.org/schema/p
                 xsi:schemaLocation="http://www.springframework.org/schema/beans
                         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            <bean id="" class="" p:name=value p:name-ref=beanId/> </beans
    >

    map和Properties的区别:Properties的value只能是字符串。

    如果用继承定义bean,子bean的集合可以设置Merge属性为true与父bean合并。

    如果要是用构造器来初始化bean,可以在bean中使用标签指定构造参数。

    <Constructor-arg type="" index="" value="" />
  • 相关阅读:
    ATmega328P定时器详解
    成员指针与mem_fn
    引用传参与reference_wrapper
    定位new表达式与显式调用析构函数
    模板参数的“右值引用”是转发引用
    C++生成随机数
    测量C++程序运行时间
    Snmp扫描-snmpwalk、snmpcheck
    操作系统识别-python、nmap
    服务扫描-dmitry、nmap、amap和服务识别
  • 原文地址:https://www.cnblogs.com/lvxiaowei/p/4264528.html
Copyright © 2011-2022 走看看