① : @Service   用法:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

满足3个条件  首先, 1.需要在applicationContext.xml 自动扫包   :“<context:component-scan base-package="想被扫包类的包"></context:component-scan>”

                       2.在User类上面加@Service

          3.在测试类中通过getbean获得自动扫包的对象   

      注:使用自动扫包    程序会先按照类名的首字母小写来定义对象。所以在getBean获得的对象需要首字母小写。

---------------

   ②  @Autowired  用法:

满足3个条件  首先, 1.需要在applicationContext.xml    :<bean id="user" class="com.spring.Memcachaed.one.User"></bean>   

                       2. 在测试类中对User属性上面加@Autowired

          3.在测试类中通过getbean获得自动扫包的对象   

      

 

 

 

    

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄