A framework for Java application development
Combine IoC, AOP, configuration, Web MVC, and application startup as needed.
Configuration (optional)Annotations and module declarations
Startup (optional)Unified startup and packaging
Configuration (optional)Annotations and module declarations
Web MVCRouting and parameter binding
- IoC dependency injection
- AOP interception
- Lifecycle management
Compose what you need
Start with hasor-core. Add configuration, Web MVC, and startup modules as needed.
Core
An embeddable container with IoC, AOP, and lifecycle management.
Core docsConfig
Declare and wire objects with @Configuration and @Bean.
Config docsWeb MVC
Handle routing, parameter binding, and response rendering for web applications.
Web MVC docsBoot
Start standalone Java or embedded web apps and build executable JARs.
Boot docs
Development examples
After startup
- Open
/hellofor JSON - Open
/app/for the static home page.
- Start the application
- Web controller
- Service
package example;
import net.hasor.boot.Boot;
import net.hasor.boot.BootApplication;
import net.hasor.web.WebApiBinder;
import net.hasor.web.WebModule;
public class Application implements WebModule {
public static void main(String[] args) throws Exception {
try (BootApplication app = Boot.run(args, Application.class)) {
app.join();
}
}
// Serve static files from the classpath under /app/.
@Override
public void loadModule(WebApiBinder binder) {
binder.addClasspathResource("/app/**", "home");
}
}
package example;
import java.util.Collections;
import java.util.Map;
import net.hasor.core.Inject;
import net.hasor.web.annotation.Get;
import net.hasor.web.annotation.MappingTo;
@MappingTo("/hello")
public class HelloController {
@Inject
private HelloService service;
@Get
public Map<String, String> hello() {
return Collections.singletonMap("message", service.greet());
}
}
package example;
import net.hasor.config.Bean;
@Bean
public class HelloService {
public String greet() {
return "Hello, Hasor!";
}
}
