scanner

scanner

FastClasspathScanner is an uber-fast, ultra-lightweight classpath scanner for Java, Scala and other JVM languages.

This module provides class-path scanning services for MVC routes, services and applications.

dependency

<dependency>
 <groupId>org.jooby</groupId>
 <artifactId>jooby-scanner</artifactId>
 <version>1.6.6</version>
</dependency>

usage

{
  use(new Scanner());
}

This modules scan the application class-path and automatically discover and register MVC routes/controllers, Jooby.Module and Jooby.Module applications.

scan spec

By default, it scans the application package:

That’s the package where your bootstrap application belong to.

Multi-package scanning is available at construction time:

{
  use(new Scanner("foo", "bar"));
}

More complex scanning criteria are supported, not just package. To see what else is available refer to documentation.

services

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/extends MyService:

{
  use(new Scanner()
    .scan(MyService.class)
  );
}

Guava Services are also supported:

{
  use(new Scanner()
    .scan(com.google.common.util.concurrent.Service.class)
  );

  get("/guava", req -> {
    ServiceManager sm = require(ServiceManager.class);
    ...
  });

}

They are added to ServiceManager and started/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.