@Component注解

一时失言乱红尘 2023-07-17 15:34 129阅读 0赞
  1. package org.springframework.stereotype;
  2. import java.lang.annotation.Documented;
  3. import java.lang.annotation.ElementType;
  4. import java.lang.annotation.Retention;
  5. import java.lang.annotation.RetentionPolicy;
  6. import java.lang.annotation.Target;
  7. /** * Indicates that an annotated class is a "component". * Such classes are considered as candidates for auto-detection * when using annotation-based configuration and classpath scanning. * * <p>Other class-level annotations may be considered as identifying * a component as well, typically a special kind of component: * e.g. the {@link Repository @Repository} annotation or AspectJ's * {@link org.aspectj.lang.annotation.Aspect @Aspect} annotation. * * @author Mark Fisher * @since 2.5 * @see Repository * @see Service * @see Controller * @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner */
  8. @Target(ElementType.TYPE)
  9. @Retention(RetentionPolicy.RUNTIME)
  10. @Documented
  11. public @interface Component {
  12. /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. * @return the suggested component name, if any */
  13. String value() default "";
  14. }

@Component注解:

  • 该注解使用在类上面,表示这个类是一个component
  • 当使用基于注解的配置和类路径扫描时,这种类就是自动检测的候选类
  • 其他类级别的注释也可以视为标识component
  • 通常是一种特殊的组件,比如@RepositoryAspectJ@Aspect注解
    在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,129人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Spring的component注解

    component注解 把类交给spring容器让他帮忙管理,用的时候只需要用Autowired方法自动装配就好了,不需要用new方法新建对象 ![在这里插入图片描述]