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.
Preface
JFinal-eventis 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
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>JFinal-event</artifactId>
<version>3.0.0</version>
</dependency>Gradle ≥ 5.x
api("net.dreamlu:JFinal-event:3.0.0")
annotationProcessor("net.dreamlu:JFinal-event:3.0.0")Gradle < 5.x
compile("net.dreamlu:JFinal-event:3.0.0")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.
net.dreamlu.event.test.Test1Listener
net.dreamlu.event.test.Test2ListenerInitialize Plugin (v3.0.0 removed class scanning)
// 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();Create Event Class
public class AccountEvent {
private Integer id;
private String name;
private Integer age;
// getters and setters omitted
}Write Listener Method
public class Test1Listener {
@EventListener
public void listenTest1Event(AccountEvent event) {
System.out.println("AccountEvent:" + event);
}
}Dispatch Event
AccountEvent event = new AccountEvent();
event.setId(1);
event.setName("张三");
event.setAge(18);
EventKit.post(event);@EventListener Annotation Details
Example
@EventListener(events = Test1Event.class, order = 1, async = true, condition = "event.isExec()")Annotation Parameters
valueor 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
