日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

IDEA Spring框架入门实例

發布時間:2025/4/9 javascript 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IDEA Spring框架入门实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IDEA創建Spring實例比較簡單,

1.直接選擇創建Spring項目即可,會自動下載所需包。

2.src下創建所需文件

1.Person類

package com.bird.service;
import com.bird.service.PersonServer;
/**
* Created by Administrator on 2017/7/13.
*/
public class PersonServerImp implements PersonServer{

private String name;
private int age;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

@Override
public void save() {
System.out.println("name:"+getName()+"age:"+getAge());
}
}

2.測試類test

package com.bird.service;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* Created by Administrator on 2017/7/13.
*/
public class test {
public static void main(String[] args){
ApplicationContext apc = new ClassPathXmlApplicationContext("beans.xml");
PersonServerImp p = (PersonServerImp)apc.getBean("personService");
p.save();
}
}

3.beans.xml,這個文件名可自己設置,在 ApplicationContext apc = new ClassPathXmlApplicationContext("beans.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="personService" class="com.bird.service.PersonServerImp">
<property name="name" value="xiaoyue"/>
<property name="age" value="25"/>
</bean>
</beans>


4.運行

?

這就是所謂的控制反轉/依賴注入...

 控制反轉意思就是說,當我們調用一個方法或者類時,不再有我們主動去創建這個類的對象,控制權交給別人(spring)。

 依賴注入意思就是說,spring主動創建被調用類的對象,然后把這個對象注入到我們自己的類中,使得我們可以使用它。

?

轉載于:https://www.cnblogs.com/John-/p/7161545.html

總結

以上是生活随笔為你收集整理的IDEA Spring框架入门实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。