一,使用注解配置Spring
1.在applicationContext.xml配置文件中配置
<context : component-scan base-package = "cn.itcast.beam."></context>
<!--指定扫描的那个包下的所有的类 -->
<context:component-scan base-package="cn.itcast.beam.User"></context:component-scan>
2.再类中使用注解完成配置
package cn.itcast.beam;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
//本质上都是一样的,但是为了更加符合我们的思维习惯,javaee中三层架构的思想
//对象类型的注入
@Component("user&