spring随手笔记4:ref的属性

1.local属性

  引用在同一个xml的bean           只能引用bean的id

<bean id="HelloWord" class="com.ltf.captha.serviceImpl.HelloWorld" destroy-method="destory">
        <property name="date">
            <ref local="date"/>
        </property>
    </bean>
    <bean id="date" class="java.util.Date"></bean>

2.bean属性

  引用在同一个xml的bean,或者不在同一个xml的bean     bean还可以引用bean的name



<bean id="HelloWord" class="com.ltf.captha.serviceImpl.HelloWorld" destroy-method="destory">
        <property name="date">
            <ref bean="date"/>
        </property>
    </bean>
    <bean id="date" class="java.util.Date"></bean

3.parent属性

<bean id="inheritedTestBeanWithoutClass">
    <property name="name"><value>parent</value></property>
    <property name="age"><value>1</value></property>
</bean>
<bean id="inheritsWithClass" class="org.springframework.beans.DerivedTestBean"
      parent="inheritedTestBeanWithoutClass" init-method="initialize">
    <property name="name"><value>override</value></property>
    <!-- age should inherit value of 1 from parent -->
</bean>
时间: 2024-08-03 16:57:59

spring随手笔记4:ref的属性的相关文章

spring随手笔记2:初始化方法

1.init-method="init" public class HelloWorldServiceImpl implements HelloWorldService { private String msg; public void init(){ this.msg="hellword"; } public void setMsg(String msg) { this.msg = msg; } public String getMsg() { return ms

spring随手笔记1:constructor-arg

<bean id="Hello" class="com.ltf.captha.serviceImpl.HelloWorldServiceImpl">        <!-- 通过构造函数进行注入 -->        <constructor-arg index="0">            <value>helloworld</value>        </construct

不错的Spring学习笔记(转)

Spring学习笔记(1)----简单的实例 ---------------------------------   首先需要准备Spring包,可从官方网站上下载.   下载解压后,必须的两个包是spring.jar和commons-logging.jar.此外为了便于测试加入了JUnit包.   在Myeclipse中创建Java项目.   编写一个接口类,为了简单,只加入了一个方法.   Java代码   1.package com.szy.spring.interfacebean;  

Spring学习笔记(一)

Spring学习笔记(一) Spring核心思想: IOC:  Inversion Of Control (控制反转) / DI: Dependency Injection (依赖注入) AOP: Aspect Oriented Programming (面向切面编程) IOC 1. 简单的应用 Model package com.wangj.spring.model; public class User { private String username; private String pas

《Spring学习笔记》:Spring、Hibernate、struts2的整合(以例子来慢慢讲解,篇幅较长)

<Spring学习笔记>:Spring.Hibernate.struts2的整合(以例子来慢慢讲解,篇幅较长) 最近在看马士兵老师的关于Spring方面的视频,讲解的挺好的,到了Spring.Hibernate.struts2整合这里,由于是以例子的形式来对Spring+Hibernate+struts2这3大框架进行整合,因此,自己还跟着写代码的过程中,发现还是遇到了很多问题,因此,就记录下. 特此说明:本篇博文完全参考于马士兵老师的<Spring视频教程>. 本篇博文均以如下这

Spring实战笔记2---Bean的装配

创建应用对象之间协作关系的行为通常成为装配,该篇的主要内容有两个,一个Spring装配Bean的几种方式以及Spring表达式,其实这两者是分不开的,在Spring中,对象无需自己负责查找或者创建与其关联的其他对象,相反容器负责把需要相互协作的对象一引用赋予各个对象,目前我们先说声明式的装配,注解式的装配等溜到下篇再详细记录,在声明用的xml配置文件中,可以使用表达式来完成一些简单的逻辑处理,和方法调用或者对象引用,在有些特殊的需求当中非它莫属,首先是装配Bean 声明Bean <bean id

spring 的配置 bean>>property>>name属性

<?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.or

(转) Spring读书笔记-----Spring的Bean之配置依赖

前一篇博客介绍了Spring中的Bean的基本概念和作用域(Spring读书笔记-----Spring的Bean之Bean的基本概念),现在介绍Spring Bean的基本配置. 从开始我们知道Java应用中各组件的相互调用的实质可以归纳为依赖关系.根据注入方式的不同,Bean的依赖注入可以分为两种形式: 1.  属性:通过<property …/>元素配置,对应设置注入. 2.  构造器参数:通过<constructor-arg…/>元素配置,对应构造注入. 不管是属性,还是构造

Spring学习笔记(三)

Spring学习笔记(三) AOP 一.使用Annotation方式实现AOP.步骤: xml里加入配置:<aop:aspectj-autoproxy /> <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org