- 浏览: 1040657 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (501)
- dwr (6)
- javascript (84)
- oracle (66)
- jsp/servlet (18)
- ant (3)
- 基础知识 (12)
- EXT (10)
- My SQL (10)
- java (71)
- spring (37)
- 学习的对象 (2)
- Linux (24)
- 面试 (1)
- HTML/CSS (11)
- tomcat (11)
- 收藏夹 (2)
- Power Designer (2)
- struts.xml配置文件 (1)
- sturts2 (3)
- myeclipse (8)
- eclipse (7)
- Maven (34)
- SVN (3)
- SAP JCO (2)
- JBOSS (11)
- webservice (8)
- word (1)
- 敏捷开发 (1)
- sybase (4)
- Nexus (3)
- EhCache (3)
- log4j (3)
- Cookie (4)
- Session (4)
- CXF (7)
- AXIS (2)
- SSO (1)
- LDAP (1)
- velocity (2)
- Jquery (5)
- redis (2)
- http (4)
- dojo (1)
- Linux资源监控软件mnon的安装与运用 (1)
- notepad++ (1)
- EA (1)
- UML (1)
- JasperReports (1)
- 权限 (0)
- freemarker (4)
- Spring MVC (1)
- JMS (1)
- activeMQ (1)
- hession (3)
- 安全 (1)
- ibatis (2)
- log (1)
- nginx (1)
最新评论
-
winhbb:
我刚好遇到了一个问题(在可以依赖注入的场合有效):有两个模块A ...
解决Maven项目相互依赖/循环依赖/双向依赖的问题 -
nanjiwubing123:
long3ok 写道你好 XmlOutputFormatter ...
用XStream转换复杂XML -
zhoujianboy:
另外一个方法实现eclipse tomcat 热部署:http ...
eclipse下实现maven项目在tomcat容器热部署方法 -
long3ok:
你好 XmlOutputFormatter 请问这个类是在什么 ...
用XStream转换复杂XML -
ganbo:
总结的好,文章给力。
解决Maven项目相互依赖/循环依赖/双向依赖的问题
在Spring中已经定义了五个标准事件,分别介绍如下:
1)ContextRefreshedEvent:当ApplicationContext初始化或者刷新时触发该事件。
2)ContextClosedEvent:当ApplicationContext被关闭时触发该事件。容器被关闭时,其管理的所有单例Bean都被销毁。
3) RequestHandleEvent:在Web应用中,当一个http请求(request)结束触发该事件。
ContestStartedEvent:Spring2.5新增的事件,当容器调用ConfigurableApplicationContext的Start()方法开始/重新开始容器时触发该事件。
5)ContestStopedEvent:Spring2.5新增的事件,当容器调用ConfigurableApplicationContext的Stop()方法停止容器时触发该事件。
下面通过一个例子展示如何处理Spring内定的事件(例程3.8)。创建一个Java工程,添加Spring开发能力后,新建ioc.test包。在包中新建ApplicationEventListener类,实现ApplicationListener接口,在onApplicationEvent()方法中添加事件处理代码,如下:
在Spring配置文件中定义一个Bean,类为ApplicationEventListener,代码如下:
添加含有主方法的TesMain类,在主方法中,调用容器的相应方法,触发Spring内定事件,代码如下:
【转载地址】
http://www.blogjava.net/cmzy/archive/2008/07/25/217217.html
1)ContextRefreshedEvent:当ApplicationContext初始化或者刷新时触发该事件。
2)ContextClosedEvent:当ApplicationContext被关闭时触发该事件。容器被关闭时,其管理的所有单例Bean都被销毁。
3) RequestHandleEvent:在Web应用中,当一个http请求(request)结束触发该事件。
ContestStartedEvent:Spring2.5新增的事件,当容器调用ConfigurableApplicationContext的Start()方法开始/重新开始容器时触发该事件。
5)ContestStopedEvent:Spring2.5新增的事件,当容器调用ConfigurableApplicationContext的Stop()方法停止容器时触发该事件。
下面通过一个例子展示如何处理Spring内定的事件(例程3.8)。创建一个Java工程,添加Spring开发能力后,新建ioc.test包。在包中新建ApplicationEventListener类,实现ApplicationListener接口,在onApplicationEvent()方法中添加事件处理代码,如下:
package ioc.test; 2 3 //Import省略 4 public class ApplicationEventListener implements ApplicationListener { 5 6 public void onApplicationEvent(ApplicationEvent event) { 7 8 //如果是容器刷新事件 9 if(event instanceof ContextClosedEvent ){ 10 System.out.println(event.getClass().getSimpleName()+" 事件已发生!"); 11 }else if(event instanceof ContextRefreshedEvent ){//如果是容器关闭事件 12 System.out.println(event.getClass().getSimpleName()+" 事件已发生!"); 13 }else if(event instanceof ContextStartedEvent ){ 14 System.out.println(event.getClass().getSimpleName()+" 事件已发生!"); 15 }else if(event instanceof ContextStoppedEvent){ 16 System.out.println(event.getClass().getSimpleName()+" 事件已发生!"); 17 }else{ 18 System.out.println("有其它事件发生:"+event.getClass().getName()); 19 } 20 21 } 22 23 }
在Spring配置文件中定义一个Bean,类为ApplicationEventListener,代码如下:
<?xml version="1.0" encoding="UTF-8"?> <beans ………… <bean id="ApplicationEventListener" class="ioc.test.ApplicationEventListener" /> </beans>
添加含有主方法的TesMain类,在主方法中,调用容器的相应方法,触发Spring内定事件,代码如下:
package ioc.test; //import省略 public class TesMain { public static void main(String[] args) { AbstractApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); // ac.refresh();//触发ContextRefreshedEvent事件 ac.start(); //触发ContextStartedEvent事件 ac.stop(); //触发ContextStoppedEvent事件 ac.close(); //关闭容器,触发ContextClosedEvent事件 } }
【转载地址】
http://www.blogjava.net/cmzy/archive/2008/07/25/217217.html
发表评论
-
Spring MVC 3.1新特性 生产者、消费者请求限定
2015-06-15 07:42 669参考地址: http://www.iteye.com/to ... -
CSRF TOKEN
2015-02-14 18:02 1108package com.uncle5.pubrub.web.c ... -
Spring MVC Controller单例陷阱
2014-06-27 08:51 643Spring MVC Controller默认是 ... -
[Spring] Hessian权限认证,加密前面
2014-03-06 09:52 1571Hessian的一些基本简介已经在上一节已经全部介绍了,上一节 ... -
FieldRetrievingFactoryBean 和 MethodInvokingFactoryBean
2014-01-09 18:36 982spring提供了filed的值注入和method的返回值注入 ... -
当spring 容器初始化完成后执行某个方法 .
2014-01-08 17:40 1399在某些应用中,我们希望,当spring 容器将所有的bea ... -
spring学习之springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
2013-09-12 10:43 1169spring mvc处理方法支持如下的返回方式:ModelA ... -
JSR-303
2013-09-12 00:22 893JSR-303 是JAVA EE 6 中的一项子规范,叫做Be ... -
EHCACHE分布式缓存
2013-09-06 17:26 1272从1.2版本开始,Ehcache可 ... -
springMVC+freemarker整合
2013-09-06 16:39 1384springMVC整合大家都比较熟悉了吧主要有以下几个步骤: ... -
Spring MVC 学习笔记 Viewresol和View
2013-09-06 15:34 894Spring MVC使用ViewResolver来根据cont ... -
Spring的PropertyPlaceholderConfigurer应用
2013-09-06 15:04 3171Spring 利用PropertyPlaceholderCon ... -
SpringSecurity3_Logout
2013-08-22 16:07 2541Logout¶•退出登录的链接 <a href=&quo ... -
spring的default-lazy-init参数 .
2013-04-23 20:08 951spring在启动的时候,会默认加载会默认加载整个对象实例图, ... -
Spring MVC 如何防止XSS、SQL注入攻击
2013-04-16 15:40 1632在Web项目中,通常需要处理XSS,SQL注入攻击,解决这个问 ... -
Spring JMS
2013-01-08 10:48 919http://blog.csdn.net/shiqiang12 ... -
给spring jdbctemplate加上一层“绮丽外衣”-动态SQL&&SQL语句以文件存放
2013-01-07 16:00 3272给spring jdbctemplate加上一层“华丽外衣”- ... -
使用Spring的NamedParameterJdbcTemplate完成DAO操作 .
2013-01-07 14:54 1141NamedParameterJdbcTemplate内部包含了 ... -
cron表达式(quartz中时间表达式)
2012-12-20 15:54 910http://sosuny.iteye.com/blog/46 ... -
spring 3中新增的@value注解
2012-11-26 22:31 3352在spring 3.0中,可以通过使用@value,对一些如x ...
相关推荐
Spring中ApplicationContext加载机制
Spring中ApplicationContext对事件传递
spring的Applicationcontext对事件的监听,在一个applicationContext范围内,实现类似MQ的效果
Spring中ApplicationContext和beanfactory区别.rar
主要介绍了 Spring获取ApplicationContext对象工具类的实现方法的相关资料,希望通过本文能帮助到大家,让大家实现这样的功能,需要的朋友可以参考下
spring 获得applicationcontext公用方法
Spring ApplicationContext 事件机制
NULL 博文链接:https://canfly2010.iteye.com/blog/443063
Spring[applicationContext.xml]灵活性代理
NULL 博文链接:https://ylxy3058.iteye.com/blog/2223687
Spring配置文件ApplicationContext,内容齐全,有需要的可以下载。
spring定时任务必须的包和spring配置说明
spring4的“所有jar包”+applicationContext.xml+web.xml====全套
NULL 博文链接:https://mutourenoo.iteye.com/blog/1156865
《Spring的数据源配置文件模板》applicationContext.zip
今天小编就为大家分享一篇关于spring中通过ApplicationContext getBean获取注入对象的方法实例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
这个工程主要实现了: Spring中Bean的生命周期 applicationcontext的应用(实现国际化,事件的传递)
spring2.5的applicationContext配置文件.
NULL 博文链接:https://dolphin-ygj.iteye.com/blog/368874