Backend Development 7 min read

Boost Your Java Backend with JFinal‑event: Annotation Processor Powered Event System

This article introduces JFinal‑event, a Java event‑handling plugin inspired by Spring, explains its recent migration to compile‑time annotation processing for faster startup, provides detailed Maven/Gradle integration steps, and demonstrates how to define, listen to, and dispatch custom events with code examples.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Boost Your Java Backend with JFinal‑event: Annotation Processor Powered Event System

Preface

JFinal-event

is modeled after Spring's

Event

usage to give JFinal users more convenience. Its core goal is deep decoupling, saving developers time for personal life.

The feature originated from a six‑month effort on Gitee issue #IR96V and has now been fully optimized.

Changelog

2019-07-19 v3.0.0

Upgraded to JFinal 4.3.

Completed optimization #IR96V 2: moved class scanning to compile time.

Removed

ClassUtil

(hope no one relied on it).

Update Notes

This release adopts

Annotation Processor

technology, shifting runtime event‑class scanning to compile time, which speeds up service startup and reduces class‑scanning issues caused by container differences.

Usage

Maven

<code>&lt;dependency&gt;
    &lt;groupId&gt;net.dreamlu&lt;/groupId&gt;
    &lt;artifactId&gt;JFinal-event&lt;/artifactId&gt;
    &lt;version&gt;3.0.0&lt;/version&gt;
&lt;/dependency&gt;</code>

Gradle ≥ 5.x

<code>api("net.dreamlu:JFinal-event:3.0.0")
annotationProcessor("net.dreamlu:JFinal-event:3.0.0")</code>

Gradle < 5.x

<code>compile("net.dreamlu:JFinal-event:3.0.0")</code>

Note

1. Version 3.0.0 uses

Annotation Processor

, so IntelliJ IDEA must enable annotation processing. 2. For manual JAR imports (non‑Maven/Gradle), you need to inject event classes manually or create a

META-INF/dream.events

file in the classes directory.

<code>net.dreamlu.event.test.Test1Listener
net.dreamlu.event.test.Test2Listener</code>

Initialize Plugin (v3.0.0 removed class scanning)

<code>// Initialize plugin
EventPlugin plugin = new EventPlugin();
// Set asynchronous execution (default is synchronous)
plugin.async();
// Start plugin (for main method); JFinal adds it automatically.
plugin.start();
// Stop plugin (for testing); JFinal adds it automatically.
plugin.stop();</code>

Create Event Class

<code>public class AccountEvent {
    private Integer id;
    private String name;
    private Integer age;
    // getters and setters omitted
}</code>

Write Listener Method

<code>public class Test1Listener {
    @EventListener
    public void listenTest1Event(AccountEvent event) {
        System.out.println("AccountEvent:" + event);
    }
}</code>

Dispatch Event

<code>AccountEvent event = new AccountEvent();
event.setId(1);
event.setName("张三");
event.setAge(18);
EventKit.post(event);</code>

@EventListener Annotation Details

Example

<code>@EventListener(events = Test1Event.class, order = 1, async = true, condition = "event.isExec()")</code>

Annotation Parameters

value

or

events

: array of event types (must extend

ApplicationEvent

or a custom base).

order

: execution order, smaller values run first; default is

Integer.MAX_VALUE

.

async

: run asynchronously; requires plugin.async() or a custom thread pool.

condition

: SpEL expression like

event.xxx

or

event.isExec() == true

to filter events.

Review

This may be the final version of JFinal-event; the author has stopped updating JFinal plugins to focus on other projects. A brief timeline of JFinal-event releases from 2015 to 2019 is listed.

Final Note

The author now devotes time to a new open‑source Spring Cloud microservice core package mica and invites readers to star the project.

BackendJavaJFinalAnnotationProcessorEventPlugin
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.