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="" />
  • 相关阅读:
    js中 var let const 区别
    img标签src引用网络图片,响应403的解决方法
    统计开发push数据
    gp日志查看
    node之path模块
    算法相关问题
    常用的 curl 发送 http 请求 命令
    Python与Go列表切片越界的对比
    golang时间与时区相关操作总结
    go语言结构体转map的方法
  • 原文地址:https://www.cnblogs.com/lvxiaowei/p/4264528.html
Copyright © 2011-2022 走看看