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
Eventusage 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 Processortechnology, 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><dependency>
<groupId>net.dreamlu</groupId>
<artifactId>JFinal-event</artifactId>
<version>3.0.0</version>
</dependency></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.eventsfile 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
valueor
events: array of event types (must extend
ApplicationEventor 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.xxxor
event.isExec() == trueto 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.
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.