一、域模型
先從最底層開(kāi)始,把域模型建立起來(lái),創(chuàng)建一個(gè)Plug-in project -
domain里面的logic,引用了dao,dao也引用了domain,會(huì)導(dǎo)致一個(gè)錯(cuò)誤,于是將logic做為一個(gè)獨(dú)立的bundle,就稱(chēng)為域邏輯吧
二、域邏輯
創(chuàng)建一個(gè)Plug-in project - org.phrancol.osgi.jpetstore.domain.logic,不創(chuàng)建Activator,創(chuàng)建一個(gè)同名package,將jpetstore\src\org\springframework\samples\jpetstore\domain\logic里面的java文件copy進(jìn)去,在MANIFEST.MF里面把依賴(lài)包導(dǎo)入
三、DAO
該做dao部分了,創(chuàng)建一個(gè) Plug-in project - org.phrancol.osgi.jpetstore.dao 并創(chuàng)建一個(gè)同名package,將jpetstore\src\org\springframework\samples\jpetstore\dao里面的東西全部copy進(jìn)去,在MANIFEST.MF里面導(dǎo)入依賴(lài)包(有一些包需要導(dǎo)入成bundle,例如 spring-jdbc,spring-ibatis),啟動(dòng)看看,發(fā)現(xiàn)spring-ibatis和persistence沒(méi)有啟動(dòng),手動(dòng)啟動(dòng)spring-ibatis,發(fā)現(xiàn)缺少ibatis,于是 New-> Other -> Plug-in from existing JAR archives ,導(dǎo)入ibatis,再啟動(dòng),發(fā)現(xiàn)少 javax.transaction,于是用相同方法導(dǎo)入。
四、配置文件
關(guān)于spring的配置文件,只有3個(gè)
petstore-servlet.xml - 用于mvc的,定義dispatch bean
applicationContext.xml - 用于域邏輯的
dataAccessContext-local.xml - 用于DAO的,定義了DataSource
(一)dataAccessContext-local.xml
1,將 jdbc.properties和sql-map-config.xml拷貝到META-INF目錄里,sql-map-config.xml里面的資源路徑可能需要修改一下,maps里面的模型的class屬性也需要改一下
2,在META-INF目錄中創(chuàng)建一個(gè)目錄spring,將dataAccessContext-local.xml拷貝進(jìn)去,將applicationContext.xml里面的加載jdbc.properties的bean移植過(guò)來(lái),放在DataSource的上面







再把dataAccessContext-local.xml里面的dao-bean->class屬性值修改一下,再把sqlMapClient的configLocation的值修改成META-INF/sql-map-config.xml,例如















(二)applicationContext.xml
1,在org.phrancol.osgi.jpetstore.domain.logic的META-INF目錄中創(chuàng)建一個(gè)目錄spring,將applicationContext.xml拷貝進(jìn)去,并改名為 logic-context.xml,刪除propertyConfigurer這個(gè)bean,因?yàn)樗呀?jīng)被移到了dataAccessContext-local.xml里面,將里面的bean的class屬性修改一下,啟動(dòng),發(fā)現(xiàn)缺少org.aspectj,導(dǎo)入一個(gè),再啟動(dòng),報(bào)錯(cuò)

2,org.phrancol.osgi.jpetstore.dao/META-INF/spring目錄中創(chuàng)建一個(gè)spring配置文件dataAccessContext-local-osgi.xml,使用<osgi:service>將accountDao和其他被引用的DAO注冊(cè)成為OSGI Service




























3,在org.phrancol.osgi.jpetstore.domain.logic/META-INF/spring 也創(chuàng)建一個(gè)spring配置文件logic-context-osgi.xml,使用<osgi:reference>獲取服務(wù)


































(三)petstore-servlet.xml
最后到spring-mvc的配置文件了,在前面已經(jīng)將這個(gè)配置文件拷貝到org.phrancol.osgi.jpetstore.springmvc/META-INF/dispatcher目錄下了,并且做了一些修改,讓DispatcherServlet加載用以顯示首頁(yè)
1,新建一個(gè)package org.phrancol.osgi.jpetstore.springmvc.controller,將jpetstore\src\org\springframework\samples\jpetstore\web\spring里面的java文件拷貝進(jìn)去,將依賴(lài)包導(dǎo)入,然后在petstore-servlet.xml里面加上一個(gè)dispatch-bean,







2,看一段代碼 org.springframework.osgi.context.support.BundleContextAwareProcessor













3,再來(lái)看看這個(gè)接口org.springframework.osgi.context.BundleContextAware

4,創(chuàng)建一個(gè) Plug-in project org.phrancol.osgi.jpetstore.util,并創(chuàng)建同名package,新建一個(gè)Interface HttpServiceRegister 用于注冊(cè)Servlet或Resource,這個(gè)過(guò)程在方法 public void serviceRegister(BundleContext context);里進(jìn)行,新建一個(gè)Class BundleServiceRegister












5,生成一個(gè)類(lèi)org.phrancol.osgi.jpetstore.springmvc.SpringmvcHttpServiceRegister implements HttpServiceRegister
將Activator.start方法里的內(nèi)容拷貝到SpringmvcHttpServiceRegister.serviceRegister方法里,刪除Activator(MANIFEST.MF)
6,在org.phrancol.osgi.jpetstore.springmvc/META-INF/下建立一個(gè)目錄spring,從別的地方copy一個(gè)bean配置文件過(guò)來(lái),改名為logic-context.xml,加入如下配置








在logic-context-osgi.xml里面加上
















