Spring中的几个注入类注解

问题描述:近期新接了个项目,发现了一个特别的注解@Repository。对视三秒中。。。

呃...好吧,我承认我不认识你了。尴尬ing...

点进去看一下: 

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Repository {
    @AliasFor(
        annotation = Component.class
    )
    String value() default "";
}

@Component修饰过的。好吧,@Component扩展注解。

简单简述下忘记他的原因吧,此注解常作用于持久层,我们的持久层如下:

 

对@Compenent,@Controller,@Service,@Repository这几个注解做个(初识)总结。

@Compenent---注解类被spring扫描并注入到Spring容器中。

@Controller---@Compenent扩展注解,作用于表现(Controller)层(spring-mvc的注解)。

@Service---@Compenent扩展注解,作用于业务(Service)层。

@Repository---@Compenent扩展注解,作用于持久(dao)层。

猜你喜欢

转载自blog.csdn.net/Gavin_Java_/article/details/106762461