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容 ...
随机推荐
- Shell编程进阶 1.8 for循环
产生序列的命令 seq 1 2 3 4 5 6 7 8 9 10 seq 1 3 5 7 9 (从1开始增加2显示这个数字,到10结束) seq - 10 8 6 4 2 seq - 10 9 8 ...
- MyBatis总结四:配置文件xml详解
XML 映射配置文件 MyBatis 的配置文件包含了影响 MyBatis 行为甚深的设置(settings)和属性(properties)信息.文档的顶层结构如下: configuration 配置 ...
- str_place()替换函数
str_replace() 函数使用一个字符串替换字符串中的另一些字符. 注释:该函数对大小写敏感.请使用 str_ireplace() 执行对大小写不敏感的搜索. echo str_replace( ...
- JS jquery ajax 已看1 有用
4.form中的input可以设置为readonly和disable,请问2者有什么区别? readonly不可编辑,但可以选择和复制:值可以传递到后台 disabled不能编辑,不能复制,不能选择: ...
- Inheritance with EF Code First: Part 2 – Table per Type (TPT)
In the previous blog post you saw that there are three different approaches to representing an inher ...
- leetCode编程题
已知链表1->2->3->4,先需要删除3这个节点,请完成函数.注意,这里只给定要删除的节点3,并不知道3之前的节点是哪个,以及整个链表是什么节点. void delete(List ...
- 前端学习01-06URL
URL(Uniform Resource Locator) 统一资源定位 URL的基本组成:协议,主机名,端口号,资源名 例如: http://www.sina.com:80/index.html 相 ...
- ConcurrentHashMap的putIfAbsent
这个方法在key不存在的时候加入一个值,如果key存在就不放入,等价: if (!map.containsKey(key)) return map.put(key, value); else retu ...
- POJ 1795 DNA Laboratory (贪心+状压DP)
题意:给定 n 个 字符串,让你构造出一个最短,字典序最小的字符串,包括这 n 个字符串. 析:首先使用状压DP,是很容易看出来的,dp[s][i] 表示已经满足 s 集合的字符串以 第 i 个字符串 ...
- 自定义MVC的Helper扩展方法 转 Insus.NET
记得在开发ASP.NET时候,也经常性使用C#可以写自己义的扩展方法,如: http://www.cnblogs.com/insus/p/3154363.html 或http://www.cnblog ...