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:初始化方法的更多相关文章

  1. Spring管理的bean初始化方法的三种方式,以及@PostConstruct不起作用的原因

    1:Spring 容器中的 Bean 是有生命周期的,spring 允许 Bean 在初始化完成后以及销毁前执行特定的操作.下面是常用的三种指定特定操作的方法: 通过实现InitializingBea ...

  2. spring随手笔记3:销毁方法

    1. public class HelloWorld { private String msg; public void setMsg(String msg) { this.msg = msg; } ...

  3. Spring学习笔记之初始化和销毁方法的调用次序

    Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, a ...

  4. spring随手笔记4:ref的属性

    1.local属性 引用在同一个xml的bean           只能引用bean的id <bean id="HelloWord" class="com.ltf ...

  5. spring随手笔记1:constructor-arg

    <bean id="Hello" class="com.ltf.captha.serviceImpl.HelloWorldServiceImpl"> ...

  6. spring 在web容器启动时执行初始化方法

    开发框架:spingMVC+myBatis 解决方案:给web容器添加一个Listener类,在容器启动的时候执行Listener的“初始化”方法,在这个初始化方法中执行查询数据库的所有操作,然后将数 ...

  7. Spring在Web容器启动时执行初始化方法

    需求:在tomcat启动时开启一个定时任务. 想法:容器启动时执行方法,最容易想到的就是servlet中可以配置load-on-startup,设置一个正整数也就可以随容器一起启动. 问题:上面的方法 ...

  8. 七、spring生命周期之初始化和销毁方法

    一.通过@Bean指定初始化和销毁方法 在以往的xml中,我们是这样配置的 <bean id="exampleInitBean" class="examples.E ...

  9. Spring项目启动时执行初始化方法

    一.applicationContext.xml配置bean <bean id="sensitiveWordInitUtil" class ="com.hx.daz ...

随机推荐

  1. android IntentFilter 使用之 data过滤

    1 Intent分为两大类,显式和隐式. 显式事件,就是指通过 component Name 属性,明确指定了目标组件的事件. 比如我们新建一个Intent,指名道姓的说,此事件用于启动名为" ...

  2. struts2数据校验与国际化

    数据校验: Action里的validate()方法能校验action类所有的方法,如果有错,如:addFieldError,会自动返回到workflow校验拦截器不向下继续进行,不用return i ...

  3. nodejs学习笔记

    这里有一段废话,我写了又删,删了又写,反复了十来次,最后还是把它删除了.不用想了,那是一段牢骚话兼有煽情意思. 好了,还是把我学习nodejs的笔记记录下来吧,一来复习巩固,加深印象,二来自己实践中出 ...

  4. redis入侵

    一.前言 前段时间,在做内网影响程度评估的时候写了扫描利用小脚本,扫描后统计发现,内网中60%开放了redis6379端口的主机处于可以被利用的危险状态,因为都是一些默认配置造成的考虑到本社区大部分开 ...

  5. 四种Java线程池用法解析

    本文为大家分析四种Java线程池用法,供大家参考,具体内容如下 http://www.jb51.net/article/81843.htm 1.new Thread的弊端 执行一个异步任务你还只是如下 ...

  6. 关于css的一些知识点整理

    一.标签的类型:   行内:span.a.b.i.strong.em.   1.共处一行   2.不支持设置宽高 display:block; 转换成块 块:h1-h6 p div  ul ol 1. ...

  7. noi 1996 登山

    题目链接: http://noi.openjudge.cn/ch0206/1996/ LIS,LDS 正着做最长递增子序列,反着做最长递减子序列. http://paste.ubuntu.com/23 ...

  8. Entity Framework 第十篇 条件查询

    业务类中 我们根据条件来动态的查询 创建IQueryable接口 public IQueryable<TEntity> GetQueryable() { IQueryable<TEn ...

  9. python异常和错误(syntax errors 和 exceptions)

    语法错误 语法错误又被称解析错误 >>> for i in range(1..10):print(i) File "<stdin>", line 1 ...

  10. python走起之第四话

    本节大纲: 一:双层装饰器:一个函数可以被多层装饰器进行装饰,函数渲染(编译)从下到上,函数执行从上到下.如下程序: 1 #!/usr/bin/env python 2 #-*-coding:utf- ...