spring bean初始化

UserBean.java

package org.rockie;

import org.springframework.beans.factory.InitializingBean;

public class UserBean implements InitializingBean{
 private String username;
 private int age;
 public int getAge() {
  return age;
 }
 public void setAge(int age) {
  this.age = age;
 }
 public String getUsername() {
  return username;
 }
 public void setUsername(String username) {
  this.username = username;
 }
 public void init()
 {
  username="rockie";
  age=22;
 }
 public void afterPropertiesSet() throws Exception {
  // TODO 自动生成方法存根
  username="kissrockie";
  age=22; 
 }

}

 

--------------------------------------------------------------------------------

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


 <bean id="user" class="org.rockie.UserBean" abstract="false"
  singleton="true" lazy-init="default" autowire="default"
  dependency-check="default">
 </bean>
</beans>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Kipen/archive/2007/04/08/1556143.aspx

你可能感兴趣的:(spring,xml,bean,.net,Blog)