<?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.xsd">
<bean id="user" class="io.zekai.entity.User" >
<!--<constructor-arg type="int" value="1994"></constructor-arg>-->
<!--<constructor-arg type="String" value="大仙"></constructor-arg>-->
<property name="id" value="10000"/>
<property name="name" value="狂尊"/>
</bean>
</beans>
package io.zekai.entity;

/**
* Created by zekai on 2017/6/3.
*/
public class User {
private int id;
private String name; public User() {
} public User(int id, String name) {
this.id = id;
this.name = name;
} public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
}
package io.zekai.entity;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by zekai on 2017/6/3.
*/
public class Main {
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("./io/zekai/entity/application-context.xml");
//通过构造器 根据bean的唯一id
User user=context.getBean(User.class);
System.out.println(user.getName());
System.out.println(user.getId());
}
}
<?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.xsd">
<bean id="user" class="io.zekai.entity.User" >
<!--<constructor-arg type="int" value="1994"></constructor-arg>-->
<!--<constructor-arg type="String" value="大仙"></constructor-arg>-->
<property name="id" value="10000"/>
<property name="name" value="狂尊"/>
</bean>
<bean id="fatherUser" class="io.zekai.entity.UserFather">
<property name="fatherName" value="laodies"/>
<property name="user" ref="user"/><!--ref参考的是xml中的-->
</bean>
</beans>
package io.zekai.entity;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* Created by zekai on 2017/6/3.
*/
public class Main {
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("io/zekai/entity/application-context.xml");
UserFather user=context.getBean(UserFather.class);
System.out.println(user.getFatherName());
}
}

最新文章

  1. (转) RSA算法原理(一)
  2. 【学习】一本案例驱动的jQuery Mobile入门书
  3. 【编程题目】有 4 张红色的牌和 4 张蓝色的牌,主持人先拿任意两张,再分别在 A、B、C 三人额头上贴
  4. C++指针详解(二)
  5. Call C# code from C++
  6. schedule() 和 scheduleAtFixedRate() 的区别--转载
  7. hdu 5108
  8. JavaScript 自动分页插件 datatables
  9. 对java面向对象的初识
  10. Vulkan Tutorial 24 Descriptor pool and sets
  11. C# 图片识别
  12. 记一次 java 连接 linux ssh服务 权限验证失败的原因和解决过程
  13. [SCOI2007]修车(建图好题)
  14. 找你妹+ipad+wifi,回顾那年的经典游戏
  15. jquery 新建的元素事件绑定问题研究[转]
  16. 51单片机实现定时器00H-FFH、定时器000-255
  17. C++/VC中ANSI与UNICODE中字符定义和函数对照表
  18. 剑指offer 面试4题
  19. python练习题及实现--文件处理、date日期
  20. Dev express 笔记

热门文章

  1. UE4 Fade out Mesh
  2. js倒计时,秒倒计时,天倒计时
  3. bzoj4784 [Zjoi2017]仙人掌
  4. php生成二维码的几种方式整理及使用实例
  5. JQuery使用mousedown和mouseup简单判断鼠标按下与释放位置是否相同
  6. Supervisor: A Process Control System
  7. Linux 零拷贝技术
  8. 将 Eclipse 的配色改为黑底白字
  9. JavaScript面向对象编程—this详解
  10. hdu 1978 How many ways 记忆化搜索+DP