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="" />
  • 相关阅读:
    一、Redis源码结构
    StringUtils工具类用法
    什么是多态
    Spring事务配置的五种方式
    不错的spring学习博客
    hibernate.current_session_context_class 比较权威的解释
    搞搞hibernate.current_session_context_class
    Spring MVC @Transactional注解方式事务失效的解决办法
    spring 中 hibernate 的 2种 配置方式(新旧 2种方式)
    Spring+Hibernate整合配置 --- 比较完整的spring、hibernate 配置
  • 原文地址:https://www.cnblogs.com/lvxiaowei/p/4264528.html
Copyright © 2011-2022 走看看