小黑J2EE學(xué)習(xí)ing
我很會努力
BlogJava
首頁
新隨筆
聯(lián)系
聚合
管理
隨筆-21 評論-29 文章-0 trackbacks-0
小黑Spring學(xué)習(xí)(二)
搭建與測試Spring的開發(fā)環(huán)境
使用版本為Spring2.5.6
新建一個Java Project 命名為spring 并導(dǎo)入相關(guān)的jar包
配置Spring配置文件
在src下新建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-2.5.xsd"
>
</
beans
>
實例化Spring容器
建議用方法一
新建一個單元測試SpringTest,并導(dǎo)入測試所用的包
package junit.test;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import cn.itcast.service.PersonService;
public class SpringTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test public void instanceSpring(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
}
}
新建一個業(yè)務(wù)Bean
,命名為PersonServiceBean;
抽取PersonServiceBean的接口。
package
cn.itcast.service.impl;
import
cn.itcast.service.PersonService;
public
class
PersonServiceBean
implements
PersonService
{
public
void
save()
{
System.out.println(
"
我是save()方法
"
);
}
}
package
cn.itcast.service;
public
interface
PersonService
{
public
void
save();
}
在配置文件中加入如下語句實現(xiàn)
<bean id="personService" class="cn.itcast.service.impl.PersonServiceBean"></bean>
注意:編寫spring配置文件時,不能出現(xiàn)幫助信息 同通過如下方法解決
修改SpringTest代碼
package
junit.test;
import
org.junit.BeforeClass;
import
org.junit.Test;
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
import
cn.itcast.service.PersonService;
public
class
SpringTest
{
@BeforeClass
public
static
void
setUpBeforeClass()
throws
Exception
{
}
@Test
public
void
instanceSpring()
{
ApplicationContext ctx
=
new
ClassPathXmlApplicationContext(
"
beans.xml
"
);
PersonService personService
=
(PersonService)ctx.getBean(
"
personService
"
);
personService.save();
}
}
在實例化了容器之后,從容器中取得bean,再調(diào)用業(yè)務(wù)bean的save方法
執(zhí)行SpringTest文件
觀察控制臺輸出
以上證明本Spring程序運行成功!
代碼參考
/Files/luckygino/spring.rar
posted on 2009-05-06 10:25
特立獨行
閱讀(464)
評論(0)
編輯
收藏
所屬分類:
Spring框架
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發(fā)表評論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關(guān)文章:
Spring 框架的設(shè)計理念與設(shè)計模式分析(2)
小黑Spring學(xué)習(xí)(四)
小黑Spring學(xué)習(xí)(三) 編碼剖析Spring管理Bean的原理
小黑Spring學(xué)習(xí)(二)
小黑Spring學(xué)習(xí)(一)
小黑J2EE學(xué)習(xí)之路 歡迎大家觀臨! 希望大家能多指教哦!
<
2025年5月
>
日
一
二
三
四
五
六
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆分類
Hibernate框架(6)
J2EE核心技術(shù)(1)
Java 技術(shù)
Java面試題
Spring框架(5)
Struts框架(7)
數(shù)據(jù)庫
隨筆檔案
2010年6月 (2)
2009年6月 (1)
2009年5月 (17)
2009年4月 (1)
搜索
最新評論
1.?re: struts2實現(xiàn)文件上傳和下載[未登錄]
下載做來直接就在頁面把文件打開了。。
--小菜
2.?re: struts2實現(xiàn)文件上傳和下載
你這代碼量有點多,STRUTS2封裝好了,頂多15行搞定
--你這代碼量有點多
3.?re: struts2實現(xiàn)文件上傳和下載
怎么將上傳的東西在頁面上顯示出來啊
--邊城
4.?re: struts2實現(xiàn)文件上傳和下載
配置的文件 有關(guān)鍵字, 把action 中的name 換下就可以了 @陳
--采用
5.?re: struts2實現(xiàn)文件上傳和下載
大俠 ……怎么實現(xiàn)點一個文件下載一個文件,而不是固定的文件?
--pppppppppp
閱讀排行榜
1.?struts2實現(xiàn)文件上傳和下載(17518)
2.?小黑struts學(xué)習(xí)(五) Action Mapping、ActionForward和ActionForm組件學(xué)習(xí)(1626)
3.?小黑Hibernate學(xué)習(xí)(三) Session接口及get、load、persist方法(1005)
4.?ASSH框架的技術(shù)基礎(chǔ)和設(shè)計(761)
5.?Spring 框架的設(shè)計理念與設(shè)計模式分析(654)
評論排行榜
1.?struts2實現(xiàn)文件上傳和下載(27)
2.?Spring 框架的設(shè)計理念與設(shè)計模式分析(1)
3.?很開心加入BlogJava 就像找到了組織一樣(1)
4.?Spring 框架的設(shè)計理念與設(shè)計模式分析(2)(0)
5.?JFreeChart的中文亂碼問題 知道的幫忙解決一下(0)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 特立獨行
主站蜘蛛池模板:
亚洲AV永久无码精品水牛影视
|
精品国产日韩亚洲一区
|
亚洲视频一区在线观看
|
精品一区二区三区无码免费视频
|
亚洲中文字幕无码中文字在线
|
久久99精品免费一区二区
|
亚洲色精品88色婷婷七月丁香
|
午夜免费福利影院
|
亚洲综合色一区二区三区
|
女人18毛片水真多免费看
|
亚洲国产综合AV在线观看
|
波多野结衣一区二区免费视频
|
色综合久久精品亚洲国产
|
亚洲国产成人爱av在线播放
|
午夜不卡AV免费
|
亚洲国产精品嫩草影院在线观看
|
亚洲AV无码一区二区三区DV
|
国产精品免费高清在线观看
|
91亚洲国产成人久久精品网站
|
亚洲人成网站免费播放
|
特级毛片全部免费播放
|
中文字幕亚洲综合久久男男
|
久久99青青精品免费观看
|
亚洲一级视频在线观看
|
免费国产成人高清视频网站
|
插鸡网站在线播放免费观看
|
久久夜色精品国产噜噜噜亚洲AV
|
国产免费久久精品99re丫y
|
国产精品日本亚洲777
|
在线精品亚洲一区二区三区
|
3d成人免费动漫在线观看
|
亚洲国产av玩弄放荡人妇
|
中文字幕亚洲一区
|
很黄很黄的网站免费的
|
十八禁的黄污污免费网站
|
亚洲高清在线视频
|
日韩电影免费在线
|
日日麻批免费40分钟无码
|
久久亚洲国产精品
|
免费看a级黄色片
|
黄网站色视频免费在线观看的a站最新
|