Spring 简单的入门

来源:互联网 发布:知乎 董洁人品 编辑:程序博客网 时间:2024/06/05 22:36

这里写图片描述


这里写图片描述


这里写图片描述


将上面的bean,配置到Spring容器中

<?xml version="1.0" encoding="UTF-8"?><beans    xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:p="http://www.springframework.org/schema/p"    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"><bean id="user" class="com.haitao.beans.user">   <property name="name">      <value>hai tao gao ruan</value>   </property>   <property name="age">      <value>35</value>   </property>   <property name="gou" ref="dog" /></bean>  <bean id="dog" class="com.haitao.beans.dog">     <property name="namee">        <value>xiao huang</value>     </property>     <property name="size">       <value>3.5</value>     </property>  </bean></beans>

下面就测试一下


    public static void main(String[] args) {        // TODO Auto-generated method stub          ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");          user ss=  (user) context.getBean("user");          ss.getMyInfo();    }

这里写图片描述



FR:海涛高软(hunk Xu)