Top Description Methods
org.jvnet.hk2.annotations

public @Interface Service

extends Annotation
Annotations
@Retention:RUNTIME
@Target:TYPE
@Documented
@InhabitantAnnotation:default
Static Imports
java.lang.annotation.ElementType.TYPE, .RetentionPolicy.RUNTIME

Annotation placed on classes that are to be automatically added to an hk2 org.glassfish.hk2.api.ServiceLocator. A service marked with this annotation has the default scope of jakarta.inject.Singleton, but any other scope annotation placed on the class will override that default.

This annotation is read at build time using the hk2-inhabitant-generator and information about the service is placed into a file in the associated jar. The usual way to get these services into a org.glassfish.hk2.api.ServiceLocator is to use a org.glassfish.hk2.api.Populator as provided by the org.glassfish.hk2.api.DynamicConfigurationService#getPopulator() method. An easier way to do that is with the org.glassfish.hk2.utilities.ServiceLocatorUtilities#createAndPopulateServiceLocator() utility.

Authors
Jerome Dochez, Kohsuke Kawaguchi
See Also
org.glassfish.hk2.api.ClassAnalyzer

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The name of the ClassAnalyzer service that should be used to analyze this class
analyzer
()

The name of the ClassAnalyzer service that should be used to analyze this class

public String
metadata()

Additional metadata that goes into the inhabitants file.

public String
name()

Name of the service.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

analyzerback to summary
public String analyzer()

The name of the ClassAnalyzer service that should be used to analyze this class

Returns:String

The name of the ClassAnalyzer service that should be used to analyze this class

metadataback to summary
public String metadata()

Additional metadata that goes into the inhabitants file. The value is "key={value},key={value1,value2,...},..." format. This information is accessible from org.glassfish.hk2.api.Descriptor#getMetadata().

While this is limited in expressiveness, metadata has a performance advantage in it that it can be read without even creating a classloader for this class. For example, this feature is used by the configuration module so that the config file can be read without actually loading the classes.

nameback to summary
public String name()

Name of the service.

org.glassfish.hk2.api.ServiceLocator#getService(Class, String, java.lang.annotation.Annotation...) and similar methods can be used to obtain a service with a particular name.

The default value "" indicates that the inhabitant has no name.