Annotation Type Metainf.Service


  • @Documented
    @Retention(SOURCE)
    public static @interface Metainf.Service
    META-INF/services/<interface.fully.qualified.name> entries in classpath will be generated with fully qualified name of annotated class as content line. Multiple meta-services by the same interface will end up on separate lines in the same meta-inf service file.

    Most other such generators either allow only single service type to be specified or just do autodetection of all interfaces. This generator supports autodetection of implemented inter (the default) or to override with one or more specific interfaces or classes.

     package a;
     @Provider
     @Metainf.Service
     public class JaxrsMessageBodyProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
     ...
     }
     
    Both META-INF/services/javax.ws.rs.ext.MessageBodyReader and META-INF/services/javax.ws.rs.ext.MessageBodyWriter will be generated and will contain line with fully qualified class name of a.JaxrsMessageBodyProvider.
     package b;
     @Provider
     @Metainf.Service(javax.ws.rs.ext.MessageBodyReader.class)
     public class JaxrsMessageBodyReader extends JaxrsMessageBodyProvider {
     ...
     }
     
    Only META-INF/services/javax.ws.rs.ext.MessageBodyReader will be generated and will contain b.JaxrsMessageBodyReader line. If JaxrsMessageBodyReader and JaxrsMessageBodyProvider will be compiled together, then META-INF/services/javax.ws.rs.ext.MessageBodyReader file will have merged content, i.e. it will contain two lines:
     a.JaxrsMessageBodyProvider
     b.JaxrsMessageBodyReader
     

    See Also:
    value(), ServiceLoader, ServiceLoader.load(Class)
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.Class<?>[] value
      If value() attribute is empty (as by default) all implemented interfaces will be taken into account, otherwise only specified implemented classes will be used.
    • Element Detail

      • value

        java.lang.Class<?>[] value
        If value() attribute is empty (as by default) all implemented interfaces will be taken into account, otherwise only specified implemented classes will be used.
        Returns:
        service interfaces or abstract classes.
        Default:
        {}