Annotation Interface Scope


@Retention(RUNTIME) @Target({TYPE,METHOD}) public @interface Scope
Annotation indicating the visibility of a Bean. It can be applied to a class annotated with Component, Service or to a method annotated with Bean. It has two properties: scope name and proxy mode. The scope name is mandatory when using this annotation and can be Singleton or Prototype.

Marking a Bean with Singleton scope means that the same object for that bean will be injected/retrieved when required. Marking a Bean with Prototype scope means that every time a new object for that bean will be injected/retrieved when required.

There are exceptions to when a Prototype Bean can return the same object: for example when injecting a Prototype Bean into a Singleton Bean. In order to fix it proxy mode can be set to ON.

There are two proxy modes: ON and OFF. By default, if not setting explicitly the proxy mode it will be set to "OFF". If the proxy mode it set to ON then a Javassist proxy of the Bean type will be created.

Usage Example:


 @Scope(name = BeanScope.PROTOTYPE, proxyMode = ProxyMode.ON)
 @Component
 public class MyComponent {

 }
 
Since:
1.0
Author:
Blyzhnytsia Team
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
     
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description