① : @Service 用法:
满足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获得自动扫包的对象