Java Spring Tutorial -- Bean Definition Inheritance
2013-12-07 20:41
417 查看
package com.zxl.spring;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringApp13 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("SpringBeans.xml");
SpringBean childSpringBean=(SpringBean)context.getBean("chlidSpringBean");
System.out.println("---------using childSpringBean01 instance----------");
System.out.println(childSpringBean.getProperty01());
System.out.println(childSpringBean.getProperty02());
System.out.println(childSpringBean.getProperty03());
SpringBean parentSpringBean=(SpringBean)context.getBean("parentSpringBean");
System.out.println("---------using parentSpringBean01 instance----------");
System.out.println(parentSpringBean.getProperty01());
System.out.println(parentSpringBean.getProperty02());
System.out.println(parentSpringBean.getProperty03());
context.close();
}
}
package com.zxl.spring; public class SpringBean { private String property01; private String property02; private String property03; public String getProperty01() { return property01; } public void setProperty01(String property01) { this.property01 = property01; } public String getProperty02() { return property02; } public void setProperty02(String property02) { this.property02 = property02; } public String getProperty03() { return property03; } public void setProperty03(String property03) { this.property03 = property03; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" > <bean id="parentSpringBean" class="com.zxl.spring.SpringBean"> <property name="property01" value="property01:parentSpringBean_propert01_value" /> <property name="property02" value="property02:parentSpringBean_propert02_value" /> </bean> <bean id="chlidSpringBean" class="com.zxl.spring.SpringBean" parent="parentSpringBean"> <property name="property01" value="property01:chlidSpringBean_propert01_value" /> <property name="property03" value="property03:chlidSpringBean_propert03_value" /> </bean> </beans>
相关文章推荐
- Java Spring Tutorial -- Bean Definition Inheritance for Java Collections
- java spring Bean Definition Inheritance 继承实例
- Java Spring Tutorial -- 注入Bean
- [转载]Spring Bean Definition Inheritance
- Java Spring Tutorial -- Singleton and Prototype Bean Scopes
- Java Spring Tutorial -- Factory, Static, and Constructor Bean Instantiation
- Java Spring Tutorial -- Bean Post Processors
- Java Spring Tutorial -- 基于Bean的配置 @Configuration @Bean
- Spring装配Bean之Java代码装配bean
- java取spring的bean
- Spring中基于Java的配置@Configuration和@Bean用法
- 我的第六个java程序 spring-bean
- 在 Spring中 创建 JavaBean
- Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/ServletRegistrationBean
- spring AbstractBeanDefinition创建bean类型是动态代理类的方式
- java Spring常用注解,自动扫描装配Bean
- Spring RootBeanDefinition,ChildBeanDefinition,GenericBeanDefinition
- java.lang.NoClassDefFoundError: org.springframework.beans.FatalBeanException
- 如何在JBPM的Action中访问Spring中的JavaBean
- spring中xml的javabean的配置