Spring----. ref的用法
|
HelloBean.java
|
|
package javamxj.spring.basic.ref;
public class HelloBean { public String getHello() { public void setHello(String hello) { }
|
|
HelloDate.java
|
|
package javamxj.spring.basic.ref;
import java.util.Date; public class HelloDate { private HelloBean hb; public void setDate(Date date) { public void setHb(HelloBean hb) { public void sayHello() { } |
beans.xml
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="helloBean" class="javamxj.spring.basic.ref.HelloBean">
<property name="hello" value="Hello! Child Bean." />
</bean>
<bean id="dateBean" name="#date" class="java.util.Date"/>
<bean id="hd1" class="javamxj.spring.basic.ref.HelloDate">
<property name="hb">
<ref bean="helloBeanParent"/>
</property>
<property name="date">
<ref bean="#date"/>
<!--<ref bean="dateBean"/>-->
</property>
</bean>
<bean id="hd2" class="javamxj.spring.basic.ref.HelloDate">
<property name="hb">
<ref local="helloBean"/>
</property>
<property name="date">
<ref local="dateBean"/>
</property>
</bean>
<bean id="hd3" class="javamxj.spring.basic.ref.HelloDate">
<property name="hb">
<ref parent="helloBean"/>
</property>
<property name="date">
<bean class="java.util.Date"/>
</property>
</bean>
</beans>
|
parent.xml
|
|
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloBean" class="javamxj.spring.basic.ref.HelloBean"> <property name="hello" value="Hello! Javamxj." /> </bean> <bean id="helloBeanParent" class="javamxj.spring.basic.ref.HelloBean"> <property name="hello" value="Hello! Parent Bean." /> </bean> </beans> |
|
Main.java
|
|
package javamxj.spring.basic.ref;
import org.springframework.beans.factory.BeanFactory; public class Main { public static void main(String[] args) { HelloDate hd1 = (HelloDate) child.getBean("hd1"); hd1.sayHello(); |
Hello! Child Bean. 2005-8-10 22:25:56
Hello! Javamxj. 2005-8-10 22:25:56
Spring----. ref的用法的更多相关文章
- Spring中@Async用法详解及简单实例
Spring中@Async用法 引言: 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的:但是在处理与第三方系统交互的时候,容易造成响应迟缓的情况,之前大部分都是使用多线程来完成此类 ...
- SpringMVC +mybatis+spring 结合easyui用法及常见问题总结
SpringMVC +mybatis+spring 结合easyui用法及常见问题总结 1.FormatString的用法. 2.用postAjaxFillGrid实现dataGrid 把form表单 ...
- vue里ref ($refs)用法
ref 有三种用法: 1.ref 加在普通的元素上,用this.ref.name 获取到的是dom元素 2.ref 加在子组件上,用this.ref.name 获取到的是组件实例,可以使用组件的所有方 ...
- (转)Spring中@Async用法总结
原文:http://blog.csdn.net/blueheart20/article/details/44648667 引言: 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的: ...
- Spring中@Async用法总结
引言: 在Java应用中,绝大多数情况下都是通过同步的方式来实现交互处理的:但是在处理与第三方系统交互的时候,容易造成响应迟缓的情况,之前大部分都是使用多线程来完成此类任务,其实,在Spring 3. ...
- spring AOP的用法
AOP,面向切面编程,它能把与核心业务逻辑无关的散落在各处并且重复的代码给封装起来,降低了模块之间的耦合度,便于维护.具体的应用场景有:日志,权限和事务管理这些方面.可以通过一张图来理解下: Spri ...
- Spring中@Value用法收集
一.配置方式 @Value需要参数,这里参数可以是两种形式: @Value("#{configProperties['t1.msgname']}") 或者 @Value(" ...
- Spring.Net简单用法
Spring.Net其实就是抽象工厂,只不过更加灵活强大,性能上并没有明显的区别. 它帮我们实现了控制反转. 其有两种依赖注入方式. 第一:属性注入 第二:构造函数注入 首先,我们去 Spring. ...
- 7 -- Spring的基本用法 -- 5...
7.5 Spring容器中的Bean 7.5.1 Bean的基本定义和Bean别名 <beans.../>元素是Spring配置文件的根元素,该元素可以指定如下属性: default-la ...
- 7 -- Spring的基本用法 -- 3...
7.3 Spring 的核心机制 : 依赖注入 Spring 框架的核心功能有两个. Spring容器作为超级大工厂,负责创建.管理所有的Java对象,这些Java对象被称为Bean. Spring容 ...
随机推荐
- springmvc+spring3+hibernate4框架简单整合,简单实现增删改查功能
转自:https://blog.csdn.net/thinkingcao/article/details/52472252 C 所用到的jar包 数据库表 数据库表就不用教大家了,一张表,很简 ...
- DAY11-MYSQL多表查询
一 介绍 本节主题 多表连接查询 复合条件连接查询 子查询 准备表 #建表 create table department( id int, name ) ); create table employ ...
- Mediaplayer
Mediaplayer报错 prepareAsync called in state 1 是因为在setDataSource之前调用了prepare.因为setDataSource放到了线程里 ...
- Tomcat服务器简介
- close、flush、read、readline、seek、tell、truncate、write的使用
1.close关闭文件 f1= open("ha.log","r+",encoding="utf-8") data = f1.read() ...
- SpringMVC接收对象数组参数进行封装
前台代码:注意.contentType : "application/json; charset=utf-8",必须要设置,只有这样SpringMVC才认识这个json数组参数 f ...
- cocos2d-js 骨骼动画 3.10
近期使用了cocos动画中的骨骼动画,这里记录使用的两种方式(3.10版): 一.cocos自带的动画编辑器导出的动画 ccs.armatureDataManager.addArmatureFileI ...
- 205. Isomorphic Strings两个数组变形记,是否符合规则
[抄题]: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the ...
- Windows系统 安装 CMake
Windows系统 安装 CMake 我们的电脑系统:Windows 10 64位 安装的CMake 版本:cmake-3.6.1-win64-x64(目前最新) 下载 在CMake官网下载:cmak ...
- netty源码阅读之UnpooledByteBufAllocator
使用IDEA阅读源码Navigate下面的工具是个好东西 .可以帮助分析类的结构等 ByteBufAllocator主要用来生成三种ByteBuf :HeadBuffer,DirectBuffer,C ...