From c6f74c96c509776b59a5b65775640e95ebdf40fd Mon Sep 17 00:00:00 2001 From: Bojan Vukasovic Date: Tue, 12 Mar 2019 10:42:39 +0100 Subject: [PATCH] Added prototype and singleton annotations --- .../context/annotation/PrototypeScope.java | 34 +++++++++++++++++++ .../context/annotation/SingletonScope.java | 34 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 spring-context/src/main/java/org/springframework/context/annotation/PrototypeScope.java create mode 100644 spring-context/src/main/java/org/springframework/context/annotation/SingletonScope.java diff --git a/spring-context/src/main/java/org/springframework/context/annotation/PrototypeScope.java b/spring-context/src/main/java/org/springframework/context/annotation/PrototypeScope.java new file mode 100644 index 000000000000..403a8db23bdc --- /dev/null +++ b/spring-context/src/main/java/org/springframework/context/annotation/PrototypeScope.java @@ -0,0 +1,34 @@ +package org.springframework.context.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.beans.factory.config.ConfigurableBeanFactory; + +/** + * {@code @PrototypeScope} is a specialization of {@link Scope @Scope} for a + * standard prototype scope: "prototype". + * + *

Specifically, {@code @PrototypeScope} is a composed annotation that + * acts as a shortcut for {@code @Scope("prototype")}. + * + *

{@code @PrototypeScope} may be used as a meta-annotation to create custom + * composed annotations. + * + * @author Bojan Vukasovic + * @since 5.1 + * @see SingletonScope + * @see org.springframework.context.annotation.Scope + * @see ConfigurableBeanFactory#SCOPE_PROTOTYPE + * @see org.springframework.stereotype.Component + * @see org.springframework.context.annotation.Bean + */ +@Target({ ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public @interface PrototypeScope { +} diff --git a/spring-context/src/main/java/org/springframework/context/annotation/SingletonScope.java b/spring-context/src/main/java/org/springframework/context/annotation/SingletonScope.java new file mode 100644 index 000000000000..ce3715346ede --- /dev/null +++ b/spring-context/src/main/java/org/springframework/context/annotation/SingletonScope.java @@ -0,0 +1,34 @@ +package org.springframework.context.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.beans.factory.config.ConfigurableBeanFactory; + +/** + * {@code @SingletonScope} is a specialization of {@link Scope @Scope} for a + * standard singleton scope: "singleton". + * + *

Specifically, {@code @SingletonScope} is a composed annotation that + * acts as a shortcut for {@code @Scope("singleton")}. + * + *

{@code @SingletonScope} may be used as a meta-annotation to create custom + * composed annotations. + * + * @author Bojan Vukasovic + * @since 5.1 + * @see PrototypeScope + * @see org.springframework.context.annotation.Scope + * @see ConfigurableBeanFactory#SCOPE_SINGLETON + * @see org.springframework.stereotype.Component + * @see org.springframework.context.annotation.Bean + */ +@Target({ ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) +public @interface SingletonScope { +}