註解注入
- 註解:就是一個類,使用@註解名稱
- 開發中:使用註解 取代 xml配置文件。
@Component :取代<bean class="">
@Component("id"):取代 <bean id="" class="">
web開發,提供3個@Component註解衍生註解(功能一樣)取代<bean class="">
@Repository(“名稱”):dao層
@Service(“名稱”):service層
@Controller(“名稱”):web層
@Autowired:自動根據類型注入
@Qualifier(“名稱”):指定自動注入的id名稱
@Resource(“名稱”)
@ PostConstruct 自定義初始化
@ PreDestroy 自定義銷燬
xml配置:
例一:
例二:
例三:
例四:
例五:
例六: