Annotation Type Component


@Retention(CLASS) @Target(TYPE) public @interface Component

Marks a class the build constructs and injects, once per server.

The build finds the class, works out what its constructor and its @Autowired members need, and writes the new into the entry point it generates. Nothing is looked up at run time: there is no container, no registry and no reflection, and a dependency that cannot be satisfied is a build error that names the injection point.

@Component
public class Clock {
    public long now() { return System.currentTimeMillis(); }
}

Service and Repository mean the same thing and exist so a class can say which layer it belongs to, as they do in Spring.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The bean's name, for Qualifier.
  • Element Details

    • value

      String value
      The bean's name, for Qualifier. Empty means the class's simple name with its first letter lower-cased, which is Spring's rule.
      Default:
      ""