新聞中心
MyEclipse開(kāi)發(fā)Spring入門(mén)的操作是什么呢?那么開(kāi)始我們的講解吧:

成都創(chuàng)新互聯(lián)公司始終堅(jiān)持【策劃先行,效果至上】的經(jīng)營(yíng)理念,通過(guò)多達(dá)十余年累計(jì)超上千家客戶的網(wǎng)站建設(shè)總結(jié)了一套系統(tǒng)有效的全網(wǎng)營(yíng)銷解決方案,現(xiàn)已廣泛運(yùn)用于各行各業(yè)的客戶,其中包括:成都茶藝設(shè)計(jì)等企業(yè),備受客戶好評(píng)。
1. 新建普通 Java 項(xiàng)目 MySpringTest. 這個(gè)過(guò)程無(wú)需贅述了, 建議建項(xiàng)目的時(shí)候?qū)?src 目錄和 bin(或者classes)目錄分開(kāi), 另外提示你切換透視圖的時(shí)候一定要切換過(guò)去到 Java 透視圖, 此時(shí)默認(rèn)會(huì)在 Package Explorer 中選中剛才已經(jīng)建好的 Java Project, 但是背景為灰色.
2. 首先單擊一下左邊的 Package Explorer 中新建的 MySpringTest 項(xiàng)目來(lái)使其高亮選中, 接著點(diǎn)擊菜單項(xiàng) MyEclipse -> Add Spring Capabilities..., 接著會(huì)彈出對(duì)話框 Add Spring Capabilities 提示你設(shè)置當(dāng)前項(xiàng)目的 Spring 屬性.
對(duì)話框的***頁(yè)可以選擇全部的 Spring 框架, 這是最保險(xiǎn)的做法, 不過(guò)我們的例子只需要選中Spring 2.0 Core Libraries 就可以了. 點(diǎn)擊 "Next" 繼續(xù).
第二頁(yè)是 Add Spring bean configuration file. 保持默認(rèn)值不變就可以了. ***點(diǎn)擊 Finish.
3. Spring 的開(kāi)發(fā)沒(méi)法自動(dòng)生成 Bean, 這里大家只好手工來(lái)寫(xiě)了, 也很簡(jiǎn)單. 分別復(fù)制下面的三個(gè)代碼, 然后在 MyEclipse src 目錄上點(diǎn)擊右鍵后選擇菜單項(xiàng) Paste 就可以生成 Java 類文件了.
- public interface Action {
- public String execute(String str);
- }
- public class UpperAction implements Action {
- private String message;
- public String getMessage() {
- return message;
- }
- public void setMessage(String string) {
- message = string;
- }
- public String execute(String str) {
- return (getMessage() + str).toUpperCase();
- }
- }
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- public class TestAction {
- public static void main(String[] args) {
- ApplicationContext ctx = new ClassPathXmlApplicationContext(
- "applicationContext.xml");
- Action bean = (Action) ctx.getBean("theAction");
- System.out.println(bean.execute("Rod"));
- }
- }
4. 雙擊左側(cè)在第2步生成的 applicationContext.xml, 然后選擇菜單項(xiàng) Window -> Show View -> Other..., 在彈出的對(duì)話框中選擇 MyEclipse Enterprise Workbench 節(jié)點(diǎn)下的 Spring Beans 子節(jié)點(diǎn)打開(kāi)視圖 Spring Beans. 此視圖講出現(xiàn)在主界面的右下側(cè).
5. 展開(kāi)此視圖中的 MySpringTest 父節(jié)點(diǎn), 并選中 src/applicationContext.xml 子節(jié)點(diǎn), 在此節(jié)點(diǎn)上點(diǎn)擊右鍵并選擇彈出菜單項(xiàng)中的 New Bean 來(lái)打開(kāi) Create a new Spring bean 對(duì)話框, 并按照下圖輸入對(duì)應(yīng)的內(nèi)容.
Bean Id: [theAction]
Bean class: [UpperAction]
接下來(lái)請(qǐng)單擊一下 Tab 面板 Properties 并點(diǎn)擊其中的 Add... 按鈕, 在接下來(lái)彈出的 Property Wizard 對(duì)話框中按照下圖輸入/選擇內(nèi)容:
Name: [message]
Spring type: [value]
Type: [java.lang.String]
Value:[Hello_]
***點(diǎn)擊兩次 Finish 按鈕關(guān)閉所有向?qū)?duì)話框. 然后點(diǎn)擊菜單 File -> Save. 此時(shí)可以看到 applicationContext.xml 的內(nèi)容如下所示:
- 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-2.0.xsd">
- lazy-init="default" autowire="default" dependency-check="default">
- Hello_
然后雙擊 Package Explorer 下 MySpringTest/src/TestAction.java 打開(kāi)源代碼, 然后點(diǎn)擊菜單 Run -> Run As -> 1. Java Application, 如果沒(méi)有錯(cuò)誤的話將會(huì)出現(xiàn)如下的輸入, 您的***個(gè) Hello Spring 運(yùn)行成功了:
- log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
- log4j:WARN Please initialize the log4j system properly.
- HELLO_ROD
接著您就可以對(duì)著參考書(shū)繼續(xù)創(chuàng)建類, 修改 applicationContext.xml 做更多的練習(xí)了.
開(kāi)發(fā)整合 Hibernate 的關(guān)鍵操作點(diǎn)截圖:
1. 在數(shù)據(jù)庫(kù)瀏覽器中選擇反向工程菜單;
2. 對(duì)話框的選項(xiàng)說(shuō)明
MyEclipse開(kāi)發(fā)Spring就介紹到這里,希望對(duì)你的操作有幫助。
【編輯推薦】
- MyEclipse 6.0解決連接Oracle 10g的問(wèn)題淺析
- Myeclipse 6.0破解方法詳解
- MyEclipse6.5+Eclipse3.4的中文問(wèn)題淺析
- MyEclipse6.5漢化之葵花寶典
- MyEclipse5.5+Eclipse3.2+Tomcat5.5配置淺析
本文名稱:MyEclipse開(kāi)發(fā)Spring入門(mén)操作
網(wǎng)頁(yè)路徑:http://www.5511xx.com/article/dhdicdo.html


咨詢
建站咨詢
