zoukankan      html  css  js  c++  java
  • spring的Bean注入和P标签使用

    1.构造方法参数 对应 配置文件 <constructor-arg> 元素

    可以index|name|type 三选一 、三选二  ; ref|value 二选一

    2. setter方法注入(开发推荐)

    为需要注入属性提供setter方法

    配置 每个注入属性, 对应<property> 元素

    3. p名称空间的使用

    spring2.5以后,为了简化setter方法属性注入,引用p名称空间的概念,可以将<property> 子元素,简化为<bean>元素属性配置 !!

    a.

    在applicationContext.xml 引入p 名称空间

    <beans xmlns="http://www.springframework.org/schema/beans"

              xmlns:p="http://www.springframework.org/schema/p"

           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.xsd">

    b.  简化注入的配置

    4. 集合类型的属性注入(了解)

    Spring 对每个常用集合对象,提供单独元素完成注入

           List 对象 ---- <list> 元素

           Set 对象 ---- <set> 元素

           Map对象 ----<map>元素

           Properties 对象 ---- <props> 元素

    集合属性的注入,主要用于框架的配置 !

  • 相关阅读:
    db.Exec和db.Query的区别
    golang两种get请求获取携带参数的方式
    gin实现中间件middleware
    gin操作session
    笔札-有触动的句子
    并发的基本概念
    售货员的难题
    传球游戏之最小总代价
    状压dp入门
    [COCI 2010] OGRADA
  • 原文地址:https://www.cnblogs.com/xumaodun/p/4928136.html
Copyright © 2011-2022 走看看