三九宝宝网宝宝教育智力培养

基于SpringDM的WEB应用开发

12月22日 编辑 39baobao.com

Spring DM 1.1.x的特性便是它可以支持在其中部署WEB应用,我使用后感觉这是个很酷的特性,我甚至觉得用这种方式开发基于OSGi WEB应用比使用Spring DM Server更好,至少目前你可以获得更好的便携性(可以在多个Spring DM支持的OSGi平台上运行),并且Spring DM Server并没有提供更多的企业应用支持。

不过对于刚使用Spring DM进行WEB应用开发的人来说,成功地配置却不是一件容易的事。以下详细的讲解一下相关配置。

1 运行环境所需的Bundles:

0 ACTIVE system.bundle_3.2.2.R32x_v20070118

1 ACTIVE .springsource.slf4j.api_1.5.0

2 RESOLVED .springframework.osgi.jetty.web.extender.fragment.osgi_1.0.0

Master=46

3 ACTIVE .springframework.bundle.osgi.extender_1.0.1.v200803070100

4 ACTIVE .springframework.bundle.spring.core_2.5.5

5 ACTIVE .springframework.bundle.spring.web_2.5.5

6 ACTIVE .springsource..objectweb.asm_2.2.3

7 RESOLVED osgi_log_config_1.0.0

Master=36

8 ACTIVE .springframework.bundle.osgi.core_1.0.1.v200803070100

9 ACTIVE .springsource.slf4j.log4j_1.5.0

10 ACTIVE .springframework.bundle.spring_2.5.2.v200803070100

11 ACTIVE .springframework.bundle.spring.context_2.5.5

12 ACTIVE jax.servlet_2.4.0.v200706111738

13 ACTIVE .springframework.osgi.servlet-api.osgi_2.5.0.SNAPSHOT

14 ACTIVE .springsource..sf.cglib_2.1.3

15 ACTIVE .springframework.bundle.spring.beans_2.5.5

16 ACTIVE jax.servletp_2.0.0.v200706191603

18 ACTIVE .springframework.osgi.jetty.start.osgi_1.0.0

19 ACTIVE .springframework.bundle.osgi.io_1.0.1.v200803070100

20 ACTIVE .aopalliance_1.0.0

21 ACTIVE .springframework.bundle.spring.context.support_2.5.5

23 ACTIVE .springsource..aopalliance_1.0.0

24 ACTIVE .springframework.bundle.spring.aop_2.5.5

25 ACTIVE .springsource.slf4j..apache.mons.logging_1.5.0

30 ACTIVE .objectweb.asm_2.2.3

33 ACTIVE .mortbay.jetty.server_6.1.9

35 ACTIVE .mortbay.jetty.util_6.1.9

36 ACTIVE .springframework.osgi.log4j.osgi_1.2.15.SNAPSHOT

Fragments=7

37 ACTIVE .mortbay.jetty_5.1.11.v200706111724

43 ACTIVE .springframework.bundle.osgi.extender_1.1.2

44 ACTIVE .springframework.bundle.osgi.io_1.1.2

45 ACTIVE .springframework.bundle.osgi.web_1.1.2

46 ACTIVE .springframework.bundle.osgi.web.extender_1.1.2

Fragments=2

47 ACTIVE .springframework.bundle.osgi.core_1.1.2

以上这些Bundles可以在spring dm 1.1.2的发布包中找到,以上Bundles的start level设置为2。

2 加入Log4j日志配置Bundles

这个Bundles的目的在于提供log4j.properties,详细做法可以参考本人的”spring osgi快速入门”

3 开发WEB应用

WEB应用的开发方式和普通的WEB基本上一样,只是加入一些OSGi的配置。

大致结构如下:

META-INF

MANIFEST.MF

WEB-INF

Classes

Lib

Web.xml

applicationContext.xml

1 MANIFEST.MF配置参考:

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: Osgi_web_app Plug-in

Bundle-SymbolicName: osgi_web_app

Bundle-Version: 1.0.0

Bundle-Vendor: ccsoft

Import-Package: jax.servlet,

jax.servlet.,

jax.servlet.resources;version="2.4.0",

soft.service,

.springframework.osgi.web.context.support;version="1.1.2",

.springframework.web.context,

.springframework.web.context.support

Bundle-ClassPath: WEB-INF/classes/,

.

Require-Bundle: .springframework.bundle.osgi.core,

.springframework.bundle.osgi.io,

.springframework.bundle.spring.beans,

.springframework.bundle.spring.context,

.springframework.bundle.spring.core

2 为了在web应用中使用spring dm的IoC功能,web.xml中需要加入一些特定配置,类似于使用Spring时的配置,web.xml配置参考如下:

Simple Osgi WebApp Bundle

Simple OSGi War

contextClass

.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext

推荐阅读
图文推荐