Blog Image

Example On Event Processing  

Here we are going to explore about spring provided Event Processing to know how we can work with Event Processing in our projects.

Lets see the example:
Technologies used :-
1) java (1.8).
2) maven (3.5.2).
3) Spring (4.0.0).

Project Structure

Execute below command for creating maven project.
mvn archetype:generate -DgroupId=com.sjg

Below is the maven project structure with packages and java src files.

package com.sjg.beans;

import org.springframework.context.ApplicationEvent;

public class ReloadEvent extends ApplicationEvent {
    private String tableName;

    public ReloadEvent(Object source, String tableName) {
        this.tableName = tableName;

    public String getTableName() {
        return tableName;

package com.sjg.beans;

import org.springframework.context.ApplicationListener;

public class ReloadEventListener implements ApplicationListener<ReloadEvent> {
    private CacheManager cacheManager;

    public void onApplicationEvent(ReloadEvent event) {


    public void setCacheManager(CacheManager cacheManager) {
        this.cacheManager = cacheManager;

package com.sjg.beans;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

public class EditStateController implements ApplicationEventPublisherAware {
    private ApplicationEventPublisher publisher;

    public void editState(String stateCode, String stateName) {
        System.out.println("Updating State into database...");
        ReloadEvent reloadEvent = new ReloadEvent(this, "tblStates");

    public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
        this.publisher = publisher;


package com.sjg.beans;

public class CacheManager {
    public void reload(String tableName) {
        System.out.println("Reloading " + tableName + " data.....");
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="";

    <bean id="editStateController" class="com.sjg.beans.EditStateController" />
    <bean id="cacheManager" class="com.sjg.beans.CacheManager" />
    <bean class="com.sjg.beans.ReloadEventListener">
        <property name="cacheManager" ref="cacheManager" />


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=""; xmlns:xsi="";


  <!-- FIXME change it to the project's website -->

package com.sjg.test;

import org.springframework.context.ApplicationContext;
import com.sjg.beans.EditStateController;

public class Test {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("com/sjg/common/application-context.xml");
        EditStateController esc = context.getBean("editStateController", EditStateController.class);
        esc.editState("NY", "New York");

Please find attached the as an maven project as a reference. Feel free to pass your comments in the blog.

About author

User Image

A software developer on JDK and JEE platform. I am passionate about Java technology and always an explorer and learner in new technologies in Java. I have experience on Open Source technologies like Struts, Spring, Jsf etc.. and even strong knowledge on Integration/Distributed world like Ejb, Web Services and Restful Services.



Be the first person to write a comment for this Blog
Load More

No More Comments

Leave a Comment

Your comment has been posted and will appear soon.