标签:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xsi:schemaLocation="http://www.springframework.org/schema/beans 6 http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd" 7 > 8 9 <bean id=“myBean” class=“com.springDemo.beanDemo.BeanIntance”></bean> 10 </beans>
1 “ new com.springDemo.beanDemo.BeanIntance(); ” 2 package com.springDemo.beanDemo 3 4 public class BeanIntance{ 5 public BeanIntance myBean(){ BeanIntance intance = new BeanIntance(); intance.setBeanname = “bean,….” ; return intance } 6 private String beanName; 7 public void setBeanName(string beanName){ this.beanName = beanName; } 8 public String getBeanName(){ return beanName;} 9 10 }
ApplicationContext ctx = new classPathXmlApplicationContext(“spring-beans.xml”); // 加载spring-beans.xml 文件 BeanIntance beanIntance = (BeanIntance)ctx.getBean(“myBean”); // 读取mybean组件,
<bean id=“mybean” class=“com.springDemo.beanDemo.BeanIntance"> <constructor-arg value=“hello”/> </bean>
1 public class BeanIntance{ 2 public BeanIntance myBean(){ BeanIntance intance = new BeanIntance(); intance.setBeanname = “bean,….” ; return intance } 3 private String beanName; 4 public void setBeanName(string beanName){ this.beanName = beanName; } 5 public String getBeanName(){ return beanName;} 6 public BeanIntance( String str ){ this.beanName = str ; } 7 }
<bean id=“Sonbean” class=“com.springDemo.beanDemo.SonBeanIntance”/> <bean id=“mybean” class=“com.springDemo.beanDemo.BeanIntance"> <constructor-arg value=“hello”/> <constructor-arg ref=“Sonbean”/> </bean>
1 <bean id=“Sonbean” class=“com.springDemo.beanDemo.SonBeanIntance” scope=“protoType”/>
1 pulic class student{ 2 private String name; 3 public void setName(String name){this.name = name;} 4 public String getName(){return this.name;} 5 private int age; 6 public void setAge(int age){ this.age=age; } 7 public int getAge(){ return this.age; } 8 }
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“name” value=“liming”/> 3 <property name=“age” value=“18”/> 4 </bean>
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“name” value=“liming”/> 3 <property name=“age” value=“18”/> 4 <property name=“teacher” > 5 <bean class=“com.springDemo.beanDemo.Teacher"> 6 </property> 7 </bean>
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:p=“http://www.springframeword.org/schema/p"> 5 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student” 6 p:name=“liming” 7 p.age=“18" 8 p.teacher-ref=“Teacher" 9 /> 10 </beans>
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“studentList"> 3 <list> 4 <ref bean=“getTeacherInfo”/> 5 <ref bean=“getFirstStudnetInfo”/> 6 <ref bean=“getscondStudentInfo”/> 7 </list> 8 </property> 9 </bean>
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“studentList"> 3 <set> 4 <ref bean=“getTeacherInfo”/> 5 <ref bean=“getFirstStudentInfo”/> 6 <ref bean=“getsecondStudentInfo”/> 7 </set> 8 </property> 9 </bean>
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“studentList"> 3 <map> 4 <entry key=“getTeacher” value-ref=“getTeacherInfo" /> 5 <entry key=“getFirseStudent” value-ref=“getFirstStudentInfo" /> 6 <entry key=“getSecondStudent” value-ref=“getsecondStudentInfo" /> 7 </map> 8 </property> 9 </bean>
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“studentList"> 3 <props> 4 <prop key=“getTeacher”>getTeacherInfo”</prop> 5 <prop key=“getFirseStudent>getFirstStudentInfo</prop> 6 <prop key=“getSecondStudent”>getsecondStudentInfo”</prop> 7 </props> 8 </properties> 9 </bean>
1 <bean id=“getStudentInfo” class=“com.springDemo.beanDemo.Student”> 2 <property name=“studentList"> 3 <props> 4 <prop key=“getTeacher”>getTeacherInfo”</prop> 5 <prop key=“getFirseStudent>getFirstStudentInfo</prop> 6 <prop key=“getSecondStudent”>getsecondStudentInfo”</prop> 7 </props> 8 </properties> 9 </bean>
<property name=“student” ref=“getStudent”/>
<property name=“multiplier” value=“#(T(java.lang.Math).Random())">
标签:
原文地址:http://www.cnblogs.com/Leo_wl/p/5679675.html