Spring与OSGi集成之Web应用开发与部署
1. Web应用开发
在构建Web Bundle时,我们会利用Spring的MVC项目来接入之前创建的应用Bundle。这里会重点关注Spring - DM与Spring MVC的集成问题,如果对Spring MVC不太熟悉,需要先了解其独立使用方式。
1.1 创建控制器
Web Bundle的首要任务是创建一个控制器,用于在应用的视图和数据服务之间进行请求代理。以下是Spring OSGi应用使用的控制器代码:
package com.apress.springosgi.ch3.web;
import java.util.List;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.ui.