1 准备开发工具
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 运行SpringSource Tool Suite
a) 进入SpringSource安装目录/sts-2.9.2.RELEASE,点击STS.exe
3 创建Virgo Runtime
a) Window->Preferences->Server->Runtime Environment->add
b) 输入vi过滤,选中EclicpseRT下的Virgo Runtime,勾选Create a new local server,点击Next
c) 点击browse,选中Virgo Tomcat Server安装目录确定
4 管理Bundle依赖
a) 打开Server视图
Window->Show View->Server
b) 打开Server编辑器
在Server view中双击已创建好的Virgo Server
c) 进入Repository标签页
在Server编辑器下方点击Repository
d) 下载hibernate相关bundle
在Repository标签页左上侧输入框输入antlr->点击search,勾选输入框下方搜索结果中的bundles:com.springsource.antlr,点击Repository标签页中间下方的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服务器安装目录/Repository/usr目录下,如果不可见,尝试点击右侧Refresh按钮或右下方Update the bundle and library index链接,Virgo服务器安装目录/Repository/ext目录下存放的是服务器自带的bundle
5 开发Bundle
5.1 com.dw.test.datasource
a) 创建bundle项目
File->new->project,输入bun过滤,选中Virgo下的bundle项目->next,输入com.dw.test.datasource->next,勾选Enable Bundle Classpath Container,Target runtime下拉框选择Virgo Runtime->finish
b) 导入依赖包
双击src/META-INF/MANIFEST.MF->点击下方dependencies标签页->在Import Package区域点击Add按钮->输入com.mysql.jdbc,点击OK。按此步骤依次导入以下依赖包
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) 创建bundle项目,名为com.dw.test.domain,参考5.1 a
b)导入依赖包javax.persistence,javassist.util.proxy,org.hibernate.proxy,参考5.1 b
c) 创建并导出共享包
创建包com.dw.test.domain,打开src/META-INF/MANIFEST.MF编辑器->点击runtime标签页->在Exported Packages区域点击Add按钮->输入com.dw.test.domain,点击OK
d) 创建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) 创建bundle项目,名为com.dw.test.dao,参考5.1 a
b) 引入项目com.dw.test.domain
右键项目->点击Properties->选中Project References->勾选com.dw.test.domain->点击OK
c) 导入依赖包com.dw.test.domain,参考5.1 b
d) 创建并导出共享包com.dw.test.dao,参考5.2 c
e) 创建IBaseDao基类接口
src/com.dw.test.dao.IBaseDao
2
3
4
5
6
7
8
9
10
11
12
13
14
15
f) 创建IUserDao业务接口
src/com.dw.test.dao.IUserDao
2
3
4
5
6
7
8
5.4 com.dw.test.dao.impl
a) 创建bundle项目,名为com.dw.test.dao.impl,参考5.1 a
b) 引入项目com.dw.test.domain,com.dw.test.dao,参考5.3 b
c) 导入依赖包com.dw.test.domain,com.dw.test.dao,javax.sql,参考5.1 b
d) 导入Hibernate bundle
双击src/META-INF/MANIFEST.MF -> 点击下方dependencies标签页 -> 在Import Bundle区域点击Ad d按钮->输入 com.springsource.org.hibernate,点击OK。
e) 导入Spring库
双击src/META-INF/MANIFEST.MF -> 点击下方dependencies标签页 -> 在Import Library区域点击Ad d按钮->输入 org.springframework.spring,点击OK。
f) 实现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) 实现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) 创建bundle项目,名为com.dw.test.service,参考5.1 a
b) 引入项目com.dw.test.domain,com.dw.test.dao,参考5.3 b
c) 导入依赖包com.dw.test.domain,com.dw.test.dao,参考5.1 b
d) 创建并导出共享包com.dw.test.service,参考5.2 c
e) 创建IBaseService类接口
src/com.dw.test.service.IBaseService
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
f) 创建IUserService业务接口
src/com.dw.test.service.IUserService
2
3
4
5
6
7
5.6 com.dw.test.service.impl
a) 创建bundle项目,名为com.dw.test.service.impl,参考5.1 a
b) 引入项目com.dw.test.domain,com.dw.test.dao,com.dw.test.service参考5.3 b
c) 导入依赖包,com.dw.test.dao,com.dw.test.domain,com.dw.test.service,org.aopalliance.aop,参考5.1 b
d) 导入Hibernate bundle,参考5.4 d
e) 导入Spring库,参考5.4 e
f) 实现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) 实现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) 创建bundle项目,名为com.dw.test.web,参考5.1 a(创建过程中记得勾选Web Application Bundle,源码编译输出目录设置为WEB-INF/classes)
b) 引入项目com.dw.test.domain,com.dw.test.service,参考5.3 b
c) 导入依赖包,com.dw.test.domain,com.dw.test.service,org.eclipse.virgo.web.dm,org.slf4j,参考5.1 b
d) 导入Hibernate bundle,参考5.4 d
e) 导入Spring库,参考5.4
f) 创建控制器
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) 定义服务引用
WEB-INF/applicationContext.xml
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
j) 注意事项
com.dw.test.web项目的MANIFEST.MF文件内容有如下头信息,否则会有无法访问以及注解无效等问题
Web-ContextPath: /test
Bundle-ClassPath: WEB-INF/classes