java web 插件,Java Web应用程序"插件"建筑

Please give an advise on how to do "plugin" architecture for Java web application.

Currently we are using quite simple and standard Spring+Hibernate+Struts 2 in Tomcat servlet container. (Built with maven)

I need something like Redmine. Where any module can be enabled/disabled, updated

rlRBb.png

Please exclude heavy options like OSGi, Portlet.

OSGi is too heavy, there is no good adoption of the technology for web. I already looked at Eclipse Germini;

Portlet it just old, and never was popular.

解决方案

I will try to provide several possible solution. I did spent some time preparing small PoCs for the project I'm working on, so let's hope the options below are relevant.

Important note: it is really easy to define some extension point, do resolve and find available implementations. There are a lot of solutions available, for example good and simple one -- JSPF

Resources are the main problem for WEB applications

OSGi

OSGi, is not that bad and can be useful. It seems to be heavy (and some implementations are heavy) but this is price of standardized platform. I would suggest to check Apache Felix. It can be used in a "lightweight" mode. By the way, it includes Web Console which is build as loosely coupled plugin-based application, could be helpful:

XfmEb.png

The Web Console can be extended by registering an OSGi service for the

interface javax.servlet.Servlet with the service property

felix.webconsole.label set to the label (last segment in the URL) of

the page. The respective service is called a Web Console Plugin or a

plugin for short.

You can also check eie-manager which is clean and simple and uses OSGi to manage plugins. Could be a good example for you.

Custom plugin framework

I would suggest to review solution behind Jenkins/Hudson. I would say Jenkins plug-in system is quite mature and reliable. Can be used as a good example.

htjyK.jpg

Simple solution

For my project I've build plugin abstraction layer based on JSPF with custom dependency resolver.

PROS:

simple and small

clean concept

works good

CONS:

without proper plugin management can be slow (full classpath search)

provides very basic functionality

may require additional attention

I would suggest to use JSPF only if you really need some simplicity and want to control everything. JPF provides a lot of interesting features out of the box, for example:

Plug-ins can be "hot-registered" and even de-registered during

application execution. What's more, registered plug-ins can be

activated and deactivated "on the fly", minimizing runtime resource

usage.

The problem is JPF is dead.

Suggestion

Do spend some time with Apache Felix. It is mature enough, so your time investments may pay back a lot.

您可以在导出Excel时,将双引号替换为",可以使用Java中的字符串替换方法来实现。以下是一个简单的示例代码: ```java import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileOutputStream; import java.io.IOException; public class ExcelExporter { public static void main(String[] args) { // 创建一个工作簿 Workbook workbook = new XSSFWorkbook(); // 创建一个工作表 Sheet sheet = workbook.createSheet("Sheet1"); // 创建一个行 Row row = sheet.createRow(0); // 创建一个单元格,并设置值为带双引号的字符串 Cell cell = row.createCell(0); cell.setCellValue("Hello, \"World\"!"); // 导出Excel时将双引号替换为" String cellValue = cell.getStringCellValue().replace("\"", """); cell.setCellValue(cellValue); // 将工作簿写入文件 try (FileOutputStream outputStream = new FileOutputStream("output.xlsx")) { workbook.write(outputStream); } catch (IOException e) { e.printStackTrace(); } System.out.println("Excel导出成功!"); } } ``` 在上述代码中,我们使用了 Apache POI 库来操作 Excel 文件。首先创建一个工作簿,然后创建一个工作表和行,接着创建一个单元格,并设置它的值为带双引号的字符串。然后,使用 `replace` 方法将双引号替换为 `"`,最后将工作簿写入文件中。 请注意,为了运行此代码,您需要在项目中添加 Apache POI 的相关依赖。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值