@Component
Application ctx = new ClassPathXmlApplicationContext("applicationContext.xml");Service名称 变量 = ctx.getBean(Service名称.class);System.out,println("变量名称");
@Componentpublic class BookDaoImpl implements BookDao{}
或者
@Component("bookDao")//可以理解为idpublic class BookDaoImpl implements BookDao{}
核心配置文件中通过组件的扫描加载bean
<context:component-scan base-package="com.chentianyu" />
- @Component注解的三个衍生注解
- @Controller: 用于表现层的bean定义
- @Service: 用于业务层的bean定义
- @Repository: 用于数据层bean定义
这三个都是跟@Component功能一致,只是用来区分三层的区分
