首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

SPRING流入FIELD值

2012-10-30 
SPRING注入FIELD值Spring注入field值嘿嘿,今天偷懒,就记一点点内容,然后去看PPLIVE去!注入field值FieldRet

SPRING注入FIELD值
Spring注入field值
    嘿嘿,今天偷懒,就记一点点内容,然后去看PPLIVE去!
    注入field值
        FieldRetrievingFactoryBean用来获得目标bean的field值。获得的值可注入给其他bean,也可直接定义成新的bean.
           for example:
--------------------------------------------------------
package org.viking.spring.imp;

public class Son
{
private int age;

public int getAge() {
  return age;
}

public void setAge(int age) {
  this.age = age;
}
}
--------------------------------------------------------
<?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-2.0.xsd">

<bean id="son" + son.getAge());

}
}
--------------------------------------------------------
    下面这个是field值定义成bean实例。只需修改applicationContext.xml和测试类。
--------------------------------------------------------
<?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-2.0.xsd">

<bean id="son" + son.getAge());
  System.out.println("系统获取theAge的值: " +app.getBean("theAge"));
}

}

热点排行