Documentation

  • Simple and effective programming model for building small and large scale web applications
  • Built with developer productivity in mind
  • Plain Java DSL for routes (no xml, or similar)
  • Reflection, annotations and dependency injection are kept to a minimum and in some cases is completely optional
  • No classpath hell, the default deployment model uses a normal JVM bootstrap
  • Modules are easy to use and do as little as possible

Jooby keeps it simple yet powerful.

APPLICATION

A Jooby app looks like:

public class App extends Jooby { // 1.
{
// 2. add a route
get("/", () -> "Hello");
}
public static void main(String[] args) {
// 3. run my app
run(App::new, args);
}
}

1) Create a new App extending Jooby
2) Define your application in the instance initializer
3) Run the application.

life cycle
Application provides start and stop events. These events are useful for starting/stopping services.

onStart/onStop events
Start/stop callbacks are accessible via application:

{
onStart(() -> {
log.info("starting app");
});

onStop(() -> {
log.info("stopping app");
});

onStarted(() -> {
log.info("app started");
});
}

Or via module:

public class MyModule implements Jooby.Module {
public void configure(Env env, Config conf, Binder binder) {
env.onStart(() -> {
log.info("starting module");
});

env.onStop(() -> {
log.info("stopping module");
});

env.onStarted(() -> {
log.info("app started");
});
}

}

The onStart callbacks are part of bootstrap and executed before the server is ready. The onStarted callbacks are executed when the server is ready.

Modules are covered later all you need to know now is that you can start/stop module as you usually do from your application.

order
Callback order is preserved:

{
onStart(() -> {
log.info("first");
});

onStart(() -> {
log.info("second");
});

onStart(() -> {
log.info("third");
});

}

Order is useful for service dependencies, for example if ServiceB should be started after ServiceA.

service registry
You have access to the the service registry from start/stop events:

{
onStart(registry -> {
MyService service = registry.require(MyService.class);
service.start();
});

onStop(registry -> {
MyService service = registry.require(MyService.class);
service.stop();
});
}

PostConstruct/PreDestroy annotations
If you prefer annotations you can do:

@Singleton
public class MyService {

@PostConstruct
public void start() {
// ...
}

@PreDestroy
public void stop() {
// ...
}

}

App.java:
{
lifeCycle(MyService.class);
}

Service must be a Singleton object.