Specifies the type provided by a bean, defaulting to the actual bean type.
This allows to control how a bean is actually exposed. For instance, you might not want to expose the actual bean type which is most likely an implementation class not exported by the module and therefore not accessible to external Java modules anyway, you'd rather choose to expose a public class or an interface extended or implemented by the bean class.
This annotation can be either specified on the Bean
annotated type or on one of its a super type. In the first case, the provided type is specified by the annotation value, in the second
case, the provided type is the annotated direct super type, the annotation value being ignored. Defining a type incompatible with the actual bean type or Specifying the annotation multiple times
will result in a compilation errors.
For example, the following bean will be exposed as SomeService
outside the module. A bean can only provide one single type.
@Bean
@Provide(SomeService.class)
public class ModuleBean implements SomeService, SomeOtherService {
}
which is equivalent to:
@Bean
public class ModuleBean implements @Provide SomeService, SomeOtherService {
}
Note that this also has an impact on bean wiring. From within the module the bean provides its actual visible type which can then be wired to any assignable socket. From outside the module, wiring is only based on the provided type. There is however one exception when the annotation is used on an overridable bean, the wired type inside and outside the module is always the provided type.
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Optional Element Summary
-
Element Details
-
value
Class<?> valueSpecifies the type provided by the bean.
This type must be compatible with the actual bean type.
- Returns:
- A type
- Default:
java.lang.Object.class
-