类扫描的注解

  1、在spring的配置文件中导入命名空间

         xmlns:context="http://www.springframework.org/schema/context"
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-2.5.xsd

  2、<context:component-scan base-package="ouc.jeep.annotation.scan"></context:component-scan>

       1、 该注解解析器包含了两个功能:依赖注入和类扫描
       2、在base-package包及子包下查找所有的类

  3、如果一个类上加了@Component注解,就会进行如下的法则

        如果其value属性的值为""
              @Component
              public class Person {}
              ==
              <bean id="person" class="..Person">
       如果其value属性的值不为""
              @Component("p")
              public class Person {}
              ==
              <bean id="p" class="..Person">

  4、按照@Resource的法则再次进行操作

类扫描
@Component
@Controller:表现层
@Repository:持久化层
@Service:服务层

xml与注解比较:

   1、xml书写麻烦,但是效率高
   2、注解书写简单,但是效率低

关于继承

   1、如果一个类在spring配置文件中,但是不想让整个类创建对象,则用abstract="true"
   2、如果让一个子类拥有父类的属性,则parent="commonDao"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值