基于OSGi的Virgo Server最简单Spring web实例

简介: 基于OSGi的Virgo Server最简单Spring web实例

基于OSGi的Virgo Server最简单Spring web实例


一:开发工具下载与环境搭建


1.       下载并安装JDK6u30版本,下载地址如下:


http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downlo


ads-javase6-419409.html#jdk-6u30-oth-JPR


2.       下载并安装SpringsourceTools Suite开发IDE工具版本为2.7.2.RELEASE,下载地址:


http://download.springsource.com/release/STS/2.7.2/dist/e3.7/springsource-tool-suite-


2.7.2.RELEASE-e3.7-win32-installer.exe


3.       下载并安装VirgoServer版本为3.0.2,下载地址为:


http://www.eclipse.org/downloads/download.php?file=/virgo/release/VTS/3.0.2.RE


LEASE/virgo-tomcat-server-3.0.2.RELEASE.zip


4.      下载并安装Maven工具版本为3.03, 下载地址:


http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-3.0.3-bin.zip.


5.       打开安装好的STS(SpringSource Tools Suite)工具,Menu > Help > Install New


Software > http://subclipse.tigris.org/update_1.6.x 更新安装Virgo Server插件



二:创建WebBundle项目


将VirgoServer与maven分别解压缩到D:\osgi\project\virgo_tomcat与D:\osgi\project\maven


1.       打开STS(SpringSourceTools Suite), 选择Menu->Window->Preferences->Maven->


         Installations

1339747404_7221.png


2. 根据Wizard创建一个Mavenbundle project,在选择时候选择webapp就可以成为一个web bundle项目:

1339747497_4705.png

右键选择创建好的项目,在弹出菜单中选择SpringTools -> enable OSGi


然后再次选择SpringTools -> enable incremental generation of MANIFEST.MF file


3. 启动与访问virgoserver的splash页面


在serverview中右键选择New->server,弹出如下画面:

1339747592_5916.png


选择VirgoWeb Server点击【add】按钮以后

1339747625_7254.png


点击【finish】结束配置,点击ServerView中的启动按钮,启动VirgoServer以后


在浏览器输入http://localhost:8080即可看到如下画面

1339747668_5431.png


4.  项目布局如下:

1339747755_5442.png


5.  Web.xml内容

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>contextClass</param-name>
    <param-value>
      org.eclipse.virgo.web.dm.ServerOsgiBundleXmlWebApplicationContext
    </param-value>
  </context-param>
  <listener>
    <listener-class>
      org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>
  <servlet>
    <servlet-name>gloomyfish</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>gloomyfish</servlet-name>
    <url-pattern>/app/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
        <welcome-file>Hello.jsp</welcome-file>
    </welcome-file-list>
</web-app>

6. gloomyfish-servlet.xml内容

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
 
<context:component-scan base-package="com.gloomyfish.web" />
<!-- enable anntotation-driven controllers -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
 
<!-- configure FreeMarker support -->
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
  <property name="templateLoaderPath" value="/WEB-INF/ftl/" />
</bean>
 
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
  <property name="cache" value="true" />
  <property name="suffix" value=".ftl" />
</bean>
</beans>

打包部署项目,使用Maven编译打包以后,选择配置好的Virgo Server图标,右键[Add and Remove]


在弹出的对话框中选则项目,点击add增加到Virgo Server点击finish


1339747972_3685.png


启动运行,选择绿色运行图标,启动Virgo Sever访问如下URL:


http://localhost:8080/gloomyfish, 看到效果是一个基于HTML5的太极图案,要求在支持HTML5的


浏览器上才可以看到效果如下:

1339748002_2126.png


项目打包源代码下载地址为:

http://download.csdn.net/detail/jia20003/4375418

相关文章
|
5月前
|
缓存 安全 Java
《深入理解Spring》过滤器(Filter)——Web请求的第一道防线
Servlet过滤器是Java Web核心组件,可在请求进入容器时进行预处理与响应后处理,适用于日志、认证、安全、跨域等全局性功能,具有比Spring拦截器更早的执行时机和更广的覆盖范围。
|
6月前
|
存储 安全 Java
如何在 Spring Web 应用程序中使用 @SessionScope 和 @RequestScope
Spring框架中的`@SessionScope`和`@RequestScope`注解用于管理Web应用中的状态。`@SessionScope`绑定HTTP会话生命周期,适用于用户特定数据,如购物车;`@RequestScope`限定于单个请求,适合无状态、线程安全的操作,如日志记录。合理选择作用域能提升应用性能与可维护性。
286 1
|
7月前
|
存储 NoSQL Java
探索Spring Boot的函数式Web应用开发
通过这种方式,开发者能以声明式和函数式的编程习惯,构建高效、易测试、并发友好的Web应用,同时也能以较小的学习曲线迅速上手,因为这些概念与Spring Framework其他部分保持一致性。在设计和编码过程中,保持代码的简洁性和高内聚性,有助于维持项目的可管理性,也便于其他开发者阅读和理解。
231 0
|
Java API 数据库
构建RESTful API已经成为现代Web开发的标准做法之一。Spring Boot框架因其简洁的配置、快速的启动特性及丰富的功能集而备受开发者青睐。
【10月更文挑战第11天】本文介绍如何使用Spring Boot构建在线图书管理系统的RESTful API。通过创建Spring Boot项目,定义`Book`实体类、`BookRepository`接口和`BookService`服务类,最后实现`BookController`控制器来处理HTTP请求,展示了从基础环境搭建到API测试的完整过程。
461 4
|
8月前
|
前端开发 Java API
Spring Cloud Gateway Server Web MVC报错“Unsupported transfer encoding: chunked”解决
本文解析了Spring Cloud Gateway中出现“Unsupported transfer encoding: chunked”错误的原因,指出该问题源于Feign依赖的HTTP客户端与服务端的`chunked`传输编码不兼容,并提供了具体的解决方案。通过规范Feign客户端接口的返回类型,可有效避免该异常,提升系统兼容性与稳定性。
602 0
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
933 7
|
Java 微服务 Spring
微服务——SpringBoot使用归纳——Spring Boot中使用拦截器——拦截器使用实例
本文主要讲解了Spring Boot中拦截器的使用实例,包括判断用户是否登录和取消特定拦截操作两大场景。通过token验证实现登录状态检查,未登录则拦截请求;定义自定义注解@UnInterception实现灵活取消拦截功能。最后总结了拦截器的创建、配置及对静态资源的影响,并提供两种配置方式供选择,帮助读者掌握拦截器的实际应用。
630 0
|
Java 开发者 微服务
Spring Boot 入门:简化 Java Web 开发的强大工具
Spring Boot 是一个开源的 Java 基础框架,用于创建独立、生产级别的基于Spring框架的应用程序。它旨在简化Spring应用的初始搭建以及开发过程。
925 7
Spring Boot 入门:简化 Java Web 开发的强大工具
|
XML Java 网络架构
使用 Spring Boot 公开 SOAP Web 服务端点:详细指南
使用 Spring Boot 公开 SOAP Web 服务端点:详细指南
1737 0