- 注解:就是一个类,使用@注解名称
- 开发中:使用注解 取代 xml配置文件。
6.4.1 @Component
@component取代<bean class="">
6.4.2 @Component("id")
取代 <bean id="" class="">
6.4.4 web开发,提供3个@Component注解衍生注解(功能一样)取代<bean class="">
@Repository(“名称”):dao层
@Service(“名称”):service层
@Controller(“名称”):web层
@Autowired:自动根据类型注入
@Qualifier(“名称”):指定自动注入的id名称
@Resource(“名称”)
@ PostConstruct 自定义初始化
@ PreDestroy 自定义销毁
6.4.5 使用案例
第一个案例
|
|
|
|
|
|
|
|
第二个案例
|
|
|
|
第三个案例
|
|
|
|
第四个案例
|
|
|
|
第五个案例
|
|
第六个案例
|
|
|
|