1. Getting Started
Hasor is a lightweight framework embedded in Java applications. It manages object creation, dependency injection, configuration, AOP, events and lifecycle. Start with its core container and add annotation configuration, Web MVC and application startup modules as needed.
Four concepts connect the API: Module declares assembly rules, ApiBinder registers objects and extensions, Hasor builds the container, and AppContext holds the runtime and resolves beans. Application code uses objects created or bound by the container; closing the context ends their managed lifecycle.
Choose modules by task
| Requirement | Dependency and entry point | Read next |
|---|---|---|
| Object management and injection in ordinary Java | net.hasor:hasor-core; Module, Hasor.create().build(...) | Quick start |
| Declare beans with configuration classes and factory methods | net.hasor:hasor-config; @Configuration, @Bean, ApplicationBoot | Annotation configuration |
| Serve HTTP endpoints in an existing Servlet container | net.hasor:hasor-web; WebModule, WebApiBinder, and a Web runtime | Web MVC |
| Start an application or an embedded Web server | net.hasor:hasor-boot; add one container module for Web applications | Boot startup |
| Build an executable Fat Jar | Configure the Maven or Gradle packaging plugin; the Loader loads the archive | Project configuration |
These capabilities can be combined. hasor-config does not supply a Web container; embedded Web applications choose one of the Tomcat, Jetty or Undertow modules. Database access is provided by the separate dbVisitor integration.
Complete a first call
- Start with
hasor-coreand declare bindings withbindType(...)inModule.loadModule(ApiBinder). - Pass the Module to
Hasor.create().build(module)to obtain anAppContext. Resolve a service withgetInstance(Service.class)and call it. - Close the context when the application stops. Modules register assembly rules; use business objects after container assembly completes.
The quick start provides dependencies and code. For annotation configuration, set the scan scope with hasor.loadPackages. For Web applications, establish a Servlet or Boot runtime before registering controllers.
Runtime requirements
Hasor 5.3.0 requires JDK 17 or later. Build the source using the repository Gradle Wrapper.
Features
Hasor follows a microkernel-and-plugins design. hasor-core keeps a small core surface; hasor-web extends binding APIs through WebApiBinder; Boot extends the runtime through SPI. Companion Maven/Gradle plugins and the Loader handle executable archives.
Ordinary Java applications can use hasor-core alone. Add hasor-config for annotation configuration. Traditional Servlet Web applications add hasor-web and configure RuntimeListener and RuntimeFilter. Use Maven or Gradle packaging plugins for executable Fat Jars, adding a container module only when an embedded Web server is needed.