`
lib
  • 浏览: 133432 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

spring启动后,立即执行需要的操作

阅读更多

1、在需要进行操作的bean的xml定义中加上init-method属性,指定下启动时运行哪个方法;

2、实现InitializingBean接口,Spring在启动时会自动调用这个接口中的初始化方法

 

public class SysInitBean implements InitializingBean,ServletContextAware{
  public void afterPropertiesSet() throws Exception {
      //初始化代码
  }
}
 
实现InitializingBean接口就可以获取spring的所有配置信息。
实现ServletContextAware,可以获得servletcontext
分享到:
评论
2 楼 moment52 2012-12-13  
moment52 写道
ServletContextAware是spring的还是struts2的

是1、2都要做还是只需做1或2
1 楼 moment52 2012-12-13  
ServletContextAware是spring的还是struts2的

相关推荐

Global site tag (gtag.js) - Google Analytics