public class Scanner extends Object implements Jooby.Module
Classpath scanning services via FastClasspathScanner. FastClasspathScanner is an uber-fast, ultra-lightweight classpath scanner for Java, Scala and other JVM languages.
{
use(new Scanner());
}
This modules scan the application class-path and automatically discover and register
MVC routes/controllers and Jooby applications.
It scans the application package. That's the package where your bootstrap application belong to. Multi-package scanning is available too:
{
use(new Scanner("foo", "bar"));
}
The next example scans and initialize any class in the application package annotated with
Named:
{
use(new Scanner()
.scan(Named.class)
);
}
The next example scans and initialize any class in the application package that implements
MyService:
{
use(new Scanner()
.scan(MyService.class)
);
}
Guava Service are also supported:
{
use(new Scanner()
.scan(com.google.common.util.concurrent.Service.class)
);
get("/guava", req -> {
ServiceManager sm = req.require(ServiceManager.class);
...
});
}
They are added to ServiceManager and started and stopped automatically.
Raw/plain Guice Module are supported too
{
use(new Scanner()
.scan(Module.class)
);
}
Of course, you can combine two or more strategies:
{
use(new Scanner()
.scan(MyService.class)
.scan(Named.class)
.scan(Singleton.class)
.scan(MyAnnotation.class)
);
}
In all cases, services are created as singleton and started/stopped automatically
when PostConstruct and PreDestroy annotations are present.
| Constructor and Description |
|---|
Scanner()
Creates a new
Scanner and use the application package (a.k.a as namespace). |
Scanner(String... scanSpec)
Creates a new
Scanner and uses the provided scan spec or packages. |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(Env env,
com.typesafe.config.Config conf,
com.google.inject.Binder binder) |
Scanner |
scan(Class<?> type)
Add a scan criteria like an annotation, interface or class.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigpublic Scanner(String... scanSpec)
Scanner and uses the provided scan spec or packages.scanSpec - Scan spec or packages. See Scan
spec.public Scanner()
Scanner and use the application package (a.k.a as namespace).public void configure(Env env, com.typesafe.config.Config conf, com.google.inject.Binder binder)
configure in interface Jooby.ModuleCopyright © 2019. All rights reserved.