1.通过Spring的核心配置文件的标签<context:component-scan/>
对工程进行扫描
@Repository :用于dao层创建dao类的bean (spring2.0)
(Spring2.5)
@Component 是一个泛化的概念,仅仅表示一个组件 (Bean) ,可以作用在任何层次。
@Service 通常作用在业务层,但是目前该功能与 @Component 相同。
@Constroller 通常作用在控制层,但是目前该功能与 @Component 相同
通过在类上使用 @Repository、@Component、@Service 和 @Constroller 注解,Spring 会自动创建相应的 BeanDefinition 对象,并注册到 ApplicationContext 中。这些类就成了 Spring 受管组件。这三个注解除了作用于不同软件层次的类,其使用方式与 @Repository 是完全相同的
2.使用 @Resource、@Autowired 和 @Qualifier 指定 Bean 的自动装配策略