spring常用注解

@Autowired 自动装配通过类型  名字

如果@Autowired不能唯一自动装配上属性,则需要@Qualifier(value="xxx")

@Nullable  字段标记了这个注解  说明这个字段可以为Null

@Resource  自动装配 名字 类型

@Component  组件 放在类上  说明这个类被spring管理了  就是bean
等价于 <bean class="com.yao.pojo.User" id="user"></bean>

@Component三个衍生注解

为了更好的进行分层,Spring可以使用其它三个注解,功能一样,目前使用哪一个功能都一样。

@Controller:Controller层

@Service:service层

@Repository:dao层
@Component (pojo)

写上这些注解,就相当于将这个类交给Spring管理装配了!

  

posted @ 2021-04-07 14:55  川上富江  阅读(44)  评论(0)    收藏  举报