分散配置

来源:互联网 发布:全国ip地址数据库下载 编辑:程序博客网 时间:2024/06/11 18:12
PersonServiceBean.javapublic class PersonServiceBean {private String name;private String sex;private Integer age;private Date birth;//家庭住址private Address homeAddress;//公司地址private Address comAddress;public Address getHomeAddress() {return homeAddress;}public Address getComAddress() {return comAddress;}public void setHomeAddress(Address homeAddress) {this.homeAddress = homeAddress;}public void setComAddress(Address comAddress) {this.comAddress = comAddress;}public PersonServiceBean() {super();// TODO Auto-generated constructor stub}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public Date getBirth() {return birth;}public void setBirth(Date birth) {this.birth = birth;}public PersonServiceBean(String name, String sex, Integer age, Date birth) {super();this.name = name;this.sex = sex;this.age = age;this.birth = birth;}@Overridepublic String toString() {return "PersonServiceBean [name=" + name + ", sex=" + sex + ", age="+ age + ", birth=" + birth + "]";}}person.propertiesname=laowangsex=mxml文件<bean id="personServiceBean" class="cn.csdn.service.PersonServiceBean"><property name="name"><value>${name}</value></property><property name="sex"><value>${sex}</value></property><property name="age"><value>22</value></property><!-- 出生日期    ref属性   引用已存在的id的名称 --><property name="birth" ><ref bean="date"/></property></bean><bean id="date" class="java.util.Date"></bean><!-- 分散配置解析的后处理类         从外部文件中读取数据 --><bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>person.properties</value></list></property><property name="location"><value>person.properties</value></property></bean> 通过在xml文件中的配置就可以从外部文件中读取数据啦