我主要使用Java、Maven和Spring开发一个大型Web项目。然而,有不同风格的 Web 项目是为了满足特定客户需求而创建的。例如,如果一个客户想要一个 Twitter 页面,但另一个客户不需要,我需要能够构建带有或不带有该 Twitter 页面的该 Web 项目的风格。
我一直在研究 Maven 覆盖和 OSGi 作为两个选项。从基础覆盖层复制资源时,Maven 覆盖层往往需要很长时间才能构建。我将 Spring OSGi Web 作为一个选择,因为它们似乎走在模块化 Web 项目的小块(控制器、视图、JS/资源/图像)的正确轨道上。
OSGi 是否太过分了?这是我需要使用的吗?还有更好的吗?
I mainly develop a big Web project with Java, Maven, and Spring. However, there are different flavors of the Web project that are created for specific customer needs. For instance, if one customer wants a Twitter page, but another does not, I need to be able to build a flavor of that Web project with or without that Twitter page.
I have been looking into Maven overlays and OSGi as two options. Maven overlays tend to take a long time to build when copying resources from the base overlay. I was looking at Spring OSGi Web as an option because they seem to be on the right track for modularizing small chuncks (controllers, views, JS/resources/images) for Web projects.
Is OSGi overkill? Is it what I need to use? Is there something better?
发布评论
评论(4)
如果您需要在运行时添加/删除不可预见的功能(和代码)(而不仅仅是启用或禁用它),那么 OSGI 非常有用,但大多数时候 Web 应用程序不需要这样做。
因此,在您的情况下,只要可能,我建议使用配置(文件)来启用或禁用功能。这还有一个优点,就是你只需要一次 WAR。
要处理“如何将配置文件放入 WAR”的问题,您有多种方法( Maven war 项目中要打包的不同文件 ):
OSGI is great if you need to add/remove unforeseen features (and code) at runtime (and not just enable or disable it), but most time this is not needed for web apps.
So in your case I would recommend to use a configuration (file) to enable or disable features as long as this is possible. This also have the advantage, that you need only one WAR.
To handle the problem of: "how to put the configuration file in the WAR", you have several ways ( Different files to be packaged in a Maven war project ):
您可能对 Spring Slices 感兴趣。它基本上允许您将 Web 应用程序的片段部署为单独的包。根据您整体产品的复杂性,这可能是可取的。
我已经有一段时间没有认真看过它了,所以我不太确定它目前的状态,尽管我预计自上次查看以来它已经有了很大的改进。
任何有更多最新信息的人请随时添加链接。
http://blog.springsource.com/2009/08/ 07/slices-menu-bar-screencast/
You might be interested in Spring Slices. It basically allows you to have fragments of a web application deployed as individual bundles. Depending upon the complexity of your overall offering this may be desirable.
I've not looked at it seriously for a while, so I'm not too sure of it's current status, though I expect it's improved greatly since I last looked.
Anyone with more up to date info please feel free to add links.
http://blog.springsource.com/2009/08/07/slices-menu-bar-screencast/
Matt,根据经验,尝试只使用一个版本的应用程序,并尝试使用配置属性来管理它。
想象一下,当您有 10 个客户端,每个客户端都有一些功能,但不是两个客户端具有相同的功能集时,会发生什么情况。
Matt, as a rule of thumb, try to have only one version of your application and try to manage it with configuration properties.
Imagine what happens when you have 10 clients and each one has a couple of features, but not two clients have the same set of features.
https://github.com/griddynamics/banshun 是 Spring 的无 osgi 模块化,支持两种概念定制。它可以通过通配符拾取和实例化模块(子上下文),这称为构建时自定义,这意味着 Maven 配置文件在 WAR 中放置了必要的覆盖。相反的方法是运行时定制,当必要的模块根据属性定义时。
https://github.com/griddynamics/banshun which is osgi-less modularity for Spring supports two notions of customization. It can pickup and instantiate modules (children contexts) by wildcard that's called build time customization, implying that maven profile put necessary overlays in WAR. An opposite way is runtime customizatoin, when necessary modules are defined in according to a property.