Академический Документы
Профессиональный Документы
Культура Документы
1
ContextRefreshedEvent
2
ContextStartedEvent
3 ContextStoppedEvent
5 RequestHandledEvent
This is a web-specific event telling all beans that an HTTP request has been
serviced.
Let us have working Eclipse IDE in place and follow the following steps to
create a Spring application:
Step Description
2 Add required Spring libraries using Add External JARs option as explained in
the Spring Hello World Example chapter.
3 Create Java
classes HelloWorld, CStartEventHandler, CStopEventHandler and MainApp under
the com.tutorialspoint package.
5 The final step is to create the content of all the Java files and Bean
Configuration file and run the application as explained below.
package com.tutorialspoint;
package com.tutorialspoint;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStartedEvent;
package com.tutorialspoint;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStoppedEvent;
package com.tutorialspoint;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
obj.getMessage();
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="cStartEventHandler"
class="com.tutorialspoint.CStartEventHandler"/>
<bean id="cStopEventHandler"
class="com.tutorialspoint.CStopEventHandler"/>
</beans>
Once you are done with creating source and bean configuration files, let us
run the application. If everything is fine with your application, this will print
the following message:
ContextStartedEvent Received
Your Message : Hello World!
ContextStoppedEvent Received
If you like, you can publish your own custom events and later you can
capture the same to take any action against those custom events. If you
are interested in writing your own custom events, you can check Custom
Events in Spring