Annotation Type Service
@Retention(RUNTIME)
@Target({TYPE,CONSTRUCTOR,METHOD,PARAMETER})
@Repeatable(Services.class)
@Inherited
public @interface Service
The
Supported parameter types are the service type itself for unary references (1..1), a
Additionally it is possible to refine the cardinality by specifying the
When used on a test class, the specified services are made available for injection as parameters to all of the test's methods.
When used on a test method, the specified services are made available for injection as parameters to exactly that method.
When used on a method parameter, the specified service is made available for injection for exactly that parameter. In this case, the
@Service
annotation is to be used for test classes or methods annotated
with the @OSGi
annotation. Note that tests using this annotation are
expected to be run within an OSGi environment. It is a repeatable annotation and can
be used to specify a number of different services using the service
type
and an optional LDAP filter expression
.
Supported parameter types are the service type itself for unary references (1..1), a
Collection
or List
of the service type for optional
and multiple references (0..n).
Additionally it is possible to refine the cardinality by specifying the
cardinality
attribute in order to require or not the presence of at least one service instance, thus
achieving cardinalities (0..1) and (1..n).
When used on a test class, the specified services are made available for injection as parameters to all of the test's methods.
When used on a test method, the specified services are made available for injection as parameters to exactly that method.
When used on a method parameter, the specified service is made available for injection for exactly that parameter. In this case, the
service type
need not be specified, it can
be inferred from the parameter's type. However, it may still be useful to specify a filter expression.- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionWhether or not injection fails in the absence of a suitable service.An optional filter expression conforming to the LDAP filter syntax used in OSGiFilter
s.Class
<?> The type of the service to be injected.
-
Element Details
-
value
Class<?> valueThe type of the service to be injected.
May be omitted if the annotation is used to annotate a method parameter, as the service type can be inferred from the parameter's type.- Returns:
- the service interface or class
- Default:
java.lang.Object.class
-
filter
String filterAn optional filter expression conforming to the LDAP filter syntax used in OSGiFilter
s.- Returns:
- the filter expression or an empty string if none is specified
- Default:
""
-
cardinality
ServiceCardinality cardinalityWhether or not injection fails in the absence of a suitable service.- Returns:
- the desired cardinality for the injected service
- See Also:
- Default:
AUTO
-