- Notifications
You must be signed in to change notification settings - Fork 6
modules
There are two kinds of modules in Fathom, fathom.Module and fathom.ServletsModule.
Fathom modules are discovered by a Java ServiceLoader.
Subclass this module type to provide injectable services & components to your Fathom application.
Create a Java ServiceLoader definition file for your module...
META-INF/services/fathom.Module
com.package.MyModule
... and then define it.
publicclassMyModuleextendsModule {
@Overrideprotectedvoidsetup() {
// register MyServicebind(MyService.class);
}
}Subclass this module type to provide injectable services & components, Filters, and Servlets.
Create a Java ServiceLoader definition file for your module...
META-INF/services/fathom.ServletsModule
com.package.MyServletsModule
... and then define it.
publicclassMyServletsModuleextendsServletsModule {
@Overrideprotectedvoidsetup() {
// serve all requests with MyServletserve("/*").with(MyServlet.class);
// add a debug filter for dev modeif (getSettings().isDev()) {
filter("/*").through(MyFilter.class);
}
// register MyServicebind(MyService.class);
}
}Your module may need one or more settings to function and you may specify them as annotated requirements.
Each required setting must be present in the runtime profile configuration and must have a non-empty value otherwise the module will not be loaded.
@RequireSetting("myService.url")
@RequireSetting("myService.username")
@RequireSetting("myService.password")
publicclassMyModuleextendsModule {
@Overrideprotectedvoidinit() {
// register MyServicebind(MyService.class);
}
}You might only want to load your module in a particular runtime mode. This is easily accomplished by using one or more of the mode-specific annotations: @DEV, @TEST, and @PROD.
@DEV@TESTpublicclassDebugModuleextendsModule {
@Overrideprotectedvoidinit() {
// register DebugServicebind(DebugService.class);
}
}Add your module to the classpath of your Fathom application.