1 準(zhǔn)備開發(fā)工具
a) SpringSource Tool Suite 2.9.2.REALEASE:解壓即可
http://download.springsource.com/release/STS/2.9.2/dist/e3.7/springsource-tool-suite-2.9.2.RELEASE-e3.7.2-win32-x86_64.zip
b) Virgo Tomcat Server 3.5.0.RELEASE:解壓即可
http://eclipse.stu.edu.tw//virgo/release/VTS/3.5.0.RELEASE/virgo-tomcat-server-3.5.0.RELEASE.zip
c) Virgo插件:通過Update site安裝
http://download.eclipse.org/virgo/milestone/tooling
2 運(yùn)行SpringSource Tool Suite
a) 進(jìn)入SpringSource安裝目錄/sts-2.9.2.RELEASE,點(diǎn)擊STS.exe
3 創(chuàng)建Virgo Runtime
a) Window->Preferences->Server->Runtime Environment->add
b) 輸入vi過濾,選中EclicpseRT下的Virgo Runtime,勾選Create a new local server,點(diǎn)擊Next
c) 點(diǎn)擊browse,選中Virgo Tomcat Server安裝目錄確定
4 管理Bundle依賴
a) 打開Server視圖
Window->Show View->Server
b) 打開Server編輯器
在Server view中雙擊已創(chuàng)建好的Virgo Server
c) 進(jìn)入Repository標(biāo)簽頁
在Server編輯器下方點(diǎn)擊Repository
d) 下載hibernate相關(guān)bundle
在Repository標(biāo)簽頁左上側(cè)輸入框輸入antlr->點(diǎn)擊search,勾選輸入框下方搜索結(jié)果中的bundles:com.springsource.antlr,點(diǎn)擊Repository標(biāo)簽頁中間下方的download按鈕,依次下載如下bundle
com.springsource.antlr-2.7.6.jar
com.springsource.com.mysql.jdbc-5.1.6.jar
com.springsource.javassist-3.3.0.ga.jar
com.springsource.net.sf.cglib-2.1.3.jar
com.springsource.org.apache.commons.collections-3.2.1.jar
com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar
com.springsource.org.apache.commons.pool-1.4.0.jar
com.springsource.org.dom4j-1.6.1.jar
com.springsource.org.hibernate.annotations.common-3.3.0.ga.jar
com.springsource.org.hibernate.annotations-3.4.0.GA.jar
com.springsource.org.hibernate-3.3.1.GA.jar
com.springsource.org.jgroups-2.5.1.jar
e) 查看下載完畢的bundle
下載的bundle存放在Virgo服務(wù)器安裝目錄/Repository/usr目錄下,如果不可見,嘗試點(diǎn)擊右側(cè)Refresh按鈕或右下方Update the bundle and library index鏈接,Virgo服務(wù)器安裝目錄/Repository/ext目錄下存放的是服務(wù)器自帶的bundle
5 開發(fā)Bundle
5.1 com.dw.test.datasource
a) 創(chuàng)建bundle項(xiàng)目
File->new->project,輸入bun過濾,選中Virgo下的bundle項(xiàng)目->next,輸入com.dw.test.datasource->next,勾選Enable Bundle Classpath Container,Target runtime下拉框選擇Virgo Runtime->finish
b) 導(dǎo)入依賴包
雙擊src/META-INF/MANIFEST.MF->點(diǎn)擊下方dependencies標(biāo)簽頁->在Import Package區(qū)域點(diǎn)擊Add按鈕->輸入com.mysql.jdbc,點(diǎn)擊OK。按此步驟依次導(dǎo)入以下依賴包
com.mysql.jdbc,javax.sql,org.apache.commons.dbcp
c) 定義Spring bean
src/META-INF/spring/appContext.xml

2

3

4

5

6

7

8

9

10

11

12

13

d) 定義Spring OSGi bean
src/META-INF/spring/osgiContext.xml

2

3

4

5

6

7

8

9

10

11

5.2 com.dw.test.domain
a) 創(chuàng)建bundle項(xiàng)目,名為com.dw.test.domain,參考5.1 a
b) 導(dǎo)入依賴包javax.persistence,javassist.util.proxy,org.hibernate.proxy,參考5.1 b
c) 創(chuàng)建并導(dǎo)出共享包
創(chuàng)建包c(diǎn)om.dw.test.domain,打開src/META-INF/MANIFEST.MF編輯器->點(diǎn)擊runtime標(biāo)簽頁->在Exported Packages區(qū)域點(diǎn)擊Add按鈕->輸入com.dw.test.domain,點(diǎn)擊OK
d) 創(chuàng)建entity
src/com.dw.test.domain.User.java

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

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

5.3 com.dw.test.dao
a) 創(chuàng)建bundle項(xiàng)目,名為com.dw.test.dao,參考5.1 a
b) 引入項(xiàng)目com.dw.test.domain
右鍵項(xiàng)目->點(diǎn)擊Properties->選中Project References->勾選com.dw.test.domain->點(diǎn)擊OK
c) 導(dǎo)入依賴包com.dw.test.domain,參考5.1 b
d) 創(chuàng)建并導(dǎo)出共享包c(diǎn)om.dw.test.dao,參考5.2 c
e) 創(chuàng)建IBaseDao基類接口
src/com.dw.test.dao.IBaseDao

2

3

4

5

6

7

8

9

10

11

12

13

14

15

f) 創(chuàng)建IUserDao業(yè)務(wù)接口
src/com.dw.test.dao.IUserDao

2

3

4

5

6

7

8

5.4 com.dw.test.dao.impl
a) 創(chuàng)建bundle項(xiàng)目,名為com.dw.test.dao.impl,參考5.1 a
b) 引入項(xiàng)目com.dw.test.domain,com.dw.test.dao,參考5.3 b
c) 導(dǎo)入依賴包com.dw.test.domain,com.dw.test.dao,javax.sql,參考5.1 b
d) 導(dǎo)入Hibernate bundle
雙擊src/META-INF/MANIFEST.MF->點(diǎn)擊下方dependencies標(biāo)簽頁->在Import Bundle區(qū)域點(diǎn)擊Add按鈕->輸入com.springsource.org.hibernate,點(diǎn)擊OK。
e) 導(dǎo)入Spring庫
雙擊src/META-INF/MANIFEST.MF->點(diǎn)擊下方dependencies標(biāo)簽頁->在Import Library區(qū)域點(diǎn)擊Add按鈕->輸入org.springframework.spring,點(diǎn)擊OK。
f) 實(shí)現(xiàn)IBaseDao接口
src/com.dw.test.dao.impl.BaseDaoImpl.java

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

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

g) 實(shí)現(xiàn)IUserDao接口
src/com.dw.test.dao.impl.UserDaoImpl.java

2

3

4

5

6

7

8

9

10

11

12

h) 定義Spring Bean
src/META-INF/spring/appContext.xml

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

32

33

34

35

i) 定義OSGi bean
src/META-INF/spring/osgiContext.xml

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

5.5 com.dw.test.service
a) 創(chuàng)建bundle項(xiàng)目,名為com.dw.test.service,參考5.1 a
b) 引入項(xiàng)目com.dw.test.domain,com.dw.test.dao,參考5.3 b
c) 導(dǎo)入依賴包com.dw.test.domain,com.dw.test.dao,參考5.1 b
d) 創(chuàng)建并導(dǎo)出共享包c(diǎn)om.dw.test.service,參考5.2 c
e) 創(chuàng)建IBaseService類接口
src/com.dw.test.service.IBaseService

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

f) 創(chuàng)建IUserService業(yè)務(wù)接口
src/com.dw.test.service.IUserService

2

3

4

5

6

7

5.6 com.dw.test.service.impl
a) 創(chuàng)建bundle項(xiàng)目,名為com.dw.test.service.impl,參考5.1 a
b) 引入項(xiàng)目com.dw.test.domain,com.dw.test.dao,com.dw.test.service參考5.3 b
c) 導(dǎo)入依賴包,com.dw.test.dao,com.dw.test.domain,com.dw.test.service,org.aopalliance.aop,參考5.1 b
d) 導(dǎo)入Hibernate bundle,參考5.4 d
e) 導(dǎo)入Spring庫,參考5.4 e
f) 實(shí)現(xiàn)IBaseService接口
src/com.dw.test.service.impl.BaseServiceImpl.java

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

32

33

f) 實(shí)現(xiàn)IUserService接口
src/com.dw.test.service.impl.UserServiceImpl.java
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

g) 定義Spring Bean
src/META-INF/spring/appContext.xml

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

32

33

h) 定義OSGi bean
src/META-INF/spring/osgiContext.xml




















5.7 com.dw.test.web
a) 創(chuàng)建bundle項(xiàng)目,名為com.dw.test.web,參考5.1 a(創(chuàng)建過程中記得勾選Web Application Bundle,源碼編譯輸出目錄設(shè)置為WEB-INF/classes)
b) 引入項(xiàng)目com.dw.test.domain,com.dw.test.service,參考5.3 b
c) 導(dǎo)入依賴包,com.dw.test.domain,com.dw.test.service,org.eclipse.virgo.web.dm,org.slf4j,參考5.1 b
d) 導(dǎo)入Hibernate bundle,參考5.4 d
e) 導(dǎo)入Spring庫,參考5.4
f) 創(chuàng)建控制器
src/com.dw.test.web.controller.UserController.java

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

32

g) 定義web配置
WEB-INF/web.xml

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

32

33

h) 定義Spring MVC配置
WEB-INF/app-servlet.xml

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

32

33

34

35

36

37

38

i) 定義服務(wù)引用
WEB-INF/applicationContext.xml

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

j) 注意事項(xiàng)
com.dw.test.web項(xiàng)目的MANIFEST.MF文件內(nèi)容有如下頭信息,否則會(huì)有無法訪問以及注解無效等問題
Web-ContextPath: /test
Bundle-ClassPath: WEB-INF/classes
是否可以發(fā)下源碼,我郵箱是 baso4233@126.com
謝謝。
An Import-Package could not be resolved. Resolver error data <Import-Package: org.hibernate.mapping; version="[3.4.0.GA,3.4.0.GA]">. Caused by missing constraint in bundle <com.venusource.framework.core_1.0.0>
constraint: <Import-Package: org.hibernate.mapping; version="[3.4.0.GA,3.4.0.GA]"> constrained to bundle <com.springsource.org.hibernate> constrained bundle version range "[3.3.1.GA,3.3.1.GA]"
求源代碼,我的郵箱claytonly@163.com,謝謝了
可否發(fā)一下源碼,謝謝
qiuqiu0034@qq.com