Sun GlassFish Enterprise Server v3 Prelude Add-On Component Development Guide

Identifying a Class as an Add-On Component

Enterprise Server discovers add-on components by identifying Java programming language classes that are annotated with the org.jvnet.hk2.annotation.Service annotation.

To identify a class as an implementation of an Enterprise Server service, add the org.jvnet.hk2.annotation.Service annotation at the class-definition level of your Java programming language class.

@Service
public class SamplePlugin implements ConsoleProvider {
...
}

The @Service annotation has the following elements. All elements are optional.

name

The name of the service. The default value is an empty string.

scope

The scope to which this service implementation is tied. The default value is org.jvnet.hk2.component.PerLookup.class.

factory

The factory class for the service implementation, if the service is created by a factory class rather than by calling the default constructor. If this element is specified, the factory component is activated, and Factory.getObject is used instead of the default constructor. The default value of the factory element is org.jvnet.hk2.component.Factory.class.


Example 2–3 Example of the Optional Elements of the @Service Annotation

The following example shows how to use the optional elements of the @Service annotation:

@Service (name="MyService", 
	scope=com.example.PerRequest.class, 
	factory=com.example.MyCustomFactory)
public class SamplePlugin implements ConsoleProvider {
...
}