首页 > 编程语言 > 详细

spring随手笔记2:初始化方法

时间:2014-09-23 20:19:26      阅读:271      评论:0      收藏:0      [点我收藏+]

1.init-method="init"

public class HelloWorldServiceImpl implements HelloWorldService {

    private String msg;
    
    public void init(){
        this.msg="hellword";
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public String getMsg() {
        return msg;
    }
}
<bean id="HelloWorld" class="com.ltf.captha.serviceImpl.HelloWorldServiceImpl" init-method="init">
        <property name="msg">
            <value>helloworld</value>
        </property>
    </bean>

2.实现org.springframework.beans.factory.InitializingBean中的afterPropertiesSet

public class HelloWord implements InitializingBean{
    private String msg;
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public String getMsg() {
        return msg;
    }
    public void afterPropertiesSet() throws Exception {
        this.msg="hello";
    }

}

 

spring随手笔记2:初始化方法

原文:http://www.cnblogs.com/ltflike/p/3989016.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!