五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

spring學習筆記——注解

2020-07-28 11:48 作者:某個峙祁  | 我要投稿

##配置文件applicationContext.xml模板
```xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
? ? ? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
? ? ? xmlns:p="http://www.springframework.org/schema/p"
? ? ? xmlns:context="http://www.springframework.org/schema/context"
? ? ? xsi:schemaLocation="http://www.springframework.org/schema/beans
? ?http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
? ?http://www.springframework.org/schema/context
? ?https://www.springframework.org/schema/context/spring-context.xsd
? ?http://www.springframework.org/schema/aop
? ?https://www.springframework.org/schema/context/spring-aop.xsd">


</beans>
```
##測試類模板

@Test
? ?public void aa(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
context.getBean("");
}




##常用依賴

```xml
? ?<dependencies>
? ? ? ?<dependency>
? ? ? ? ? ?<groupId>org.springframework</groupId>
? ? ? ? ? ?<artifactId>spring-webmvc</artifactId>
? ? ? ? ? ?<version>5.2.0.RELEASE</version>
? ? ? ?</dependency>

? ? ? ?<dependency>
? ? ? ? ? ?<groupId>junit</groupId>
? ? ? ? ? ?<artifactId>junit</artifactId>
? ? ? ? ? ?<version>4.12</version>
? ? ? ?</dependency>

</dependencies>
```
##注解說明
<context:annotation-config/> ? 開啟注解支持

-@Autowired :自動裝配通過類型,名字
? ?如果Autowired不能唯一自動裝配上屬性,則需要通過@Qualifier(value ="xxx")去配置@Autowired的使用,指定一個唯一的bean對象注入
?
-@Resource :自動裝配通過名字,類型
-@Nullable :字段標記了這個注解,說明這個字段可以為null
-@Component:組件,放在類上,說明這個類被spring管理了,就是bean
-@Value() ?:括號里面為值,一般放在屬性上或者set方法上,給其賦值,屬性的注入


-@Component :有幾個衍生注解,在web開發(fā)中,會按照MVC三層架構分層
? ?dao【@Repository】
? ?service【@service】
? ?controller【@Controller】
? ?這四個注解功能都是一樣的,僅名字不同,都是代表將某個類注冊到spring容器中裝配

-Scope() :作用域的配置 ?單例模式Scope("singleton")、原型模式Scope("prototype")
? ?
? ?
? ?
? ?
##Spring注解開發(fā)
在spring4之后,要使用注解開發(fā),必須要保證aop的包導入了
使用主角需要導入context約束,注解的支持

##小結(jié)
? ?xml與注解:
? ? ? ?xml更加萬能,適用于任何場合,維護簡單方便
? ? ? ?注解 不是自己的類使用不了,維護相對復雜
? ?xml與注解最佳實踐:
? ? ? ?xml用來管理bean
? ? ? ?注解只負責屬性的注入





spring學習筆記——注解的評論 (共 條)

分享到微博請遵守國家法律
赣榆县| 泽州县| 额尔古纳市| 介休市| 邛崃市| 理塘县| 三门峡市| 镇平县| 荣昌县| 珠海市| 新安县| 青浦区| 游戏| 通江县| 兖州市| 浙江省| 正蓝旗| 离岛区| 万盛区| 静安区| 灵武市| 禹城市| 任丘市| 大邑县| 辉南县| 高陵县| 信宜市| 房产| 团风县| 和硕县| 嘉祥县| 南澳县| 正阳县| 大悟县| 荆州市| 石屏县| 额尔古纳市| 汝州市| 兴国县| 和平县| 天柱县|