Sqring核心概念
Spring? 是大規(guī)模企業(yè)級框架,用戶數(shù)量多,數(shù)據(jù)規(guī)模大,功能眾多,業(yè)務(wù)復(fù)雜,
???????????? 性能和安全要求高?? 靈活多變
???????????? Spring框架是輕量級的框架,javaEE的春天,當(dāng)前主流的框架,一站式的企業(yè)應(yīng)用開發(fā)框架
Spring 目標(biāo):是使現(xiàn)有的技術(shù)更加易用,推進(jìn)代碼的最佳實(shí)踐
Spring 內(nèi)容:IOC容器 控制反轉(zhuǎn)。
????????????????????? Aop實(shí)現(xiàn) 面向切面編程
????????????????????? 數(shù)據(jù)訪問支持? 1 簡化jdbc/orm框架
???????????????????????????????????????????? 2 聲明式事務(wù)
1. Spring容器的主要目的:降低業(yè)務(wù)邏輯層和其他層的耦合度(IOC)
2. Spring容器 用來創(chuàng)建和管理(管理對象和對象之間的關(guān)系)程序中的所有對象的實(shí)例
3. 非侵入式框架輕量級開源框架
侵入式余姚我們顯示使用框架中的API才能實(shí)現(xiàn)某種功能。--框架強(qiáng)行的將功能推送給我們。
非侵入式不需要改變我們之間的編碼。--我們資源從框架中獲取想要的功能。
Spring的核心? ( IOC? ,AOP )
IOC(Inversin Of Control)? 控制反轉(zhuǎn)
在沒有使用框架之前我們都是在Service 層創(chuàng)建dao的實(shí)例對象!控制權(quán)在service !
現(xiàn)在我們使用了Spring框架,創(chuàng)建dao的實(shí)例對象---使用Spring容器?? 控制權(quán)在 Spring容器!
這種控制權(quán)從程序的代碼中轉(zhuǎn)到Spring容器的行為就稱為 IOC 控制反轉(zhuǎn)? ?
studentDao dao=null;
public void setDao(StudentDao dao){
????? this.dao=dao;
}
Spring 容器給我們創(chuàng)建了對象的實(shí)例,然后通過setxxx(); 把對象的實(shí)例給我們需要的地方,這個過程稱為
DI依賴注入 (Dependency? Injection)
下面我們看一個Spring的小例子:
?
public class HelloSpring {private String who;//定義變量who 他的值通過Spring框架進(jìn)行注入public HelloSpring() {}public void print(){System.out.println("Hello"+this.getWho()+"okokokok!"); }public HelloSpring(String who) {this.who = who;}@Overridepublic String toString() {return "HelloSpring{" +"who='" + who + '\'' +'}';}public String getWho() {return who;}public void setWho(String who) {this.who = who;} }applicationContext.xml?? Spring容器?? <!--bean 對象聲明Spring創(chuàng)建的對象實(shí)例--> 通過Spring框架進(jìn)行注入
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="HelloSpring" class="cn.bean.HelloSpring"> <!-- 未聲明的實(shí)例對象的類 類的位置和類名--><property name="who" value="Spring hhahhahah"></property> <!-- name 被指定賦值的屬性名set 后的 。value 賦值的內(nèi)容 --></bean><!--bean 對象聲明Spring創(chuàng)建的對象實(shí)例--> public class SpringOneTest {@Testpublic void SpringHello(){ApplicationContext context=new ClassPathXmlApplicationContext("ApplicationContext.xml");//Spring 提供的接口 實(shí)現(xiàn)類 配置文件路徑HelloSpring helloSpring = (HelloSpring)context.getBean("HelloSpring");//id helloSpring.print();} }運(yùn)行結(jié)果
?
轉(zhuǎn)載于:https://www.cnblogs.com/cuixiaomeng/p/7676928.html
總結(jié)
以上是生活随笔為你收集整理的Sqring核心概念的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring boot / cloud
- 下一篇: css 外边距合并