国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用Spring框架的步驟

2019-11-15 01:07:53
字體:
來源:轉載
供稿:網友
使用SPRing框架的步驟

“好記性,不如爛筆頭”。今天正式接觸了Spring框架,第一次接觸Spring框架感覺Spring框架簡化了好多程序代碼,開發效率大大提高。現在介紹使用Spring框架的步驟。(使用spring-framework-2.5.6版本)

1、導入jar包:找到壓縮包里邊的dist/Spring.jar;然后再找到 lib/jakarta-commons/commons-logging.jar

2、編寫spring配置文件....;添加一個bean(將一個類/依賴對象交給spring來維護和創建)

<?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/beans           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">    <!--         bean:將一個類交給spring維護和創建就是一個bean        之前手動new的對象現在交給spring來做     -->    <!--<bean id="springioc" class="com.msit.spring.IOC.DI.ObjectRef.SpringIOC"></bean>-->    <!--         bean:就是一個類(對象)        property:代表類或者對象中的屬性;name跟類中的屬性名稱一樣;value就相當于=        SpringIOC.msg = "Hello-Spring"     -->    <bean id="hellospring" class="com.msit.spring.IOC.DI.propertity.HelloSpring">        <property name="msg" value="Hello-Spring"></property>    </bean>    </beans>

3、通過applicationContext context = new ClassPathXMLApplicationContext("applicationContext.xml");context.getBean("bean名稱");來獲取創建的bean

package com.msit.spring.IOC.createObject;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {    public static void main(String[] args) {        // 加載配置文件        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");                //得到Bean        HelloWorld ch = (HelloWorld) context.getBean("hellospring");        ch.hello();                //ch.createhello().hello();                //CreateHelloWorld.createhello().hello();    }}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马关县| 天祝| 蒙城县| 方正县| 南部县| 银川市| 福海县| 广水市| 亳州市| 绵竹市| 萝北县| 楚雄市| 凉山| 韶山市| 丹寨县| 广灵县| 庐江县| 尚志市| 察隅县| 镇赉县| 乡城县| 云霄县| 紫阳县| 水城县| 海原县| 阿拉善右旗| 抚顺县| 依兰县| 铁力市| 南雄市| 聂拉木县| 高邮市| 双流县| 平舆县| 文登市| 攀枝花市| 溧水县| 恩平市| 易门县| 南川市| 温泉县|