Spring 注解开发

阅读 180

2022-03-11

#常用依赖

#注解说明

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

   通过byType实现 限定值时与@qualifier(value="dsds")配套使用

@Component :组件放到类上, 说明这个类被Spring管理了,就是bean

 @Value:

三.@Component(在pojo中用)有几个衍生注解,在web开发中,会按照mvc三层架构分层!

        dao层用  @Repository

        service层用  @Service

        controller层用  @Controller

        这四个注解功能都是一样的,都代表将摸个类注册到Spring中,装配Bean

 

dao层用  @Repository

 

service层用  @Service

 

controller层用  @Controller

四,xml与注解

         xml万能适用于任何场合,维护简单

        注解维护相对复杂

      2.xml与注解的最佳时间:

           xml用来管理bean;

           注解用来负责完成属性的注入;

        3.   使用的过程中只需要注意一个问题,即必须让注解生效,需开启注解支持

                1.指定要扫描的包,这个包下的注解就会生效

                2.开启注解支持    

 

 

精彩评论(0)

0 0 举报