@Scope、@Singleton源码翻译

来源:互联网 发布:成都网络车新规 编辑:程序博客网 时间:2024/05/16 15:09

package javax.inject;import java.lang.annotation.Target;import java.lang.annotation.Retention;import java.lang.annotation.Documented;import static java.lang.annotation.RetentionPolicy.RUNTIME;import static java.lang.annotation.ElementType.ANNOTATION_TYPE;/** * 目的:定义bean的作用域 * 标识@scope注解,该注解用在可注解构造器的一个类上,决定注射器怎样重新使用实例。默认,若果没有该注解时, * 注射器通过构造器创建一个实例,之后便忽略它。使用该注解时,注入之后,注射器可能重用该实例。多线程访问域内 * 访问实例,则是线程安全的。注射器能够决定注入实例的使用范围。 *  * 以下例子,@Singleton(单例模式)注解范围用在日志实例: * @Singleton * class Log { *    void log(String message) { ... } * } * @author TCM * @create 2017年10月19日下午3:58:28 * @see javax.inject.Singleton @Singleton */@Target(ANNOTATION_TYPE)@Retention(RUNTIME)@Documentedpublic @interface Scope {}

package javax.inject;import java.lang.annotation.Documented;import java.lang.annotation.Retention;import static java.lang.annotation.RetentionPolicy.RUNTIME;/** * 目的:注解为单例实例,不能继承 * @author TCM * @create 2017年10月20日上午9:19:21 * @see javax.inject.Scope @Scope */@Scope@Documented@Retention(RUNTIME)public @interface Singleton {}