spring 架构设计

来源:互联网 发布:ubuntu jdk路径有空格 编辑:程序博客网 时间:2024/04/27 15:24
spring是一个装配工厂,装好的beans可以拿来用。<?xml version="1.0" encoding="UTF-8"?><beansxmlns="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-2.0.xsd"><!-- 创建Student实例 --><bean id="student" class="spring.student"><property name="id" value="1"></property><property name="name" value="wsp"></property></bean><bean id="teacher" parent="student"><property name="id" value="3"></property></bean></beans>
beans可继承依赖,调用语句:ApplicationContext ctx=new ClassPathXmlApplicationContext("beans1.xml");student stu=(student)ctx.getBean("student");student tea=(student)ctx.getBean("teacher");System.out.println(stu.getName()+"\t"+tea.getId());


0 0
原创粉丝点击