java - 如何在不再次部署整个程序的情况下为接口(interface)添加新的实现?

标签 java

我有一个 Web 应用程序,它根据从用户那里检索到的字符串运行不同的接口(interface)实例(执行):

public interface IExecute{
    public void run();
}

public class XExecute implements IExecute {...}

public class YExecute implements IExecute {...}

public class Handler{

    public static run(String executorName){
        IExecute executor = getImple(executorName);
        executor.run();
    }

    private static IExecute getImple(String executorName){
        return (IExecute) Class.forName(executorName+"Execute").getConstructor().newInstance();
    }
}

该程序运行正常。但是我偶尔需要在应用程序运行时添加新的 IExecute 实现。我不想在每次编写新实现时停止/启动应用程序(用于编译新源代码),因为应用程序中正在运行大量操作。 事实上,我想要一个解决方案来限制所有进程在应用程序运行时只编译新的 java 文件。任何其他解决方案,即使是复杂的解决方案也会很有帮助。

最佳答案

您能看看 OSGI 框架吗:https://www.osgi.org/developer/architecture/

据说:

The OSGi technology is a set of specifications that define a dynamic component system for Java. These specifications enable a development model where applications are (dynamically) composed of many different (reusable) components.

动态软件更新对于停机关键应用程序非常有意义,可以减少软件演化阶段的停机时间。现在越来越多的复杂应用程序在OSGi平台上开发。 Eclipse、WebSphere Liberty、JBoss、Glassfish 都在使用 OSGI 框架。

The service dynamics were added so we could install and uninstall bundles on the fly while the other bundles could adapt.

希望对您有所帮助。

关于java - 如何在不再次部署整个程序的情况下为接口(interface)添加新的实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37528902/

相关文章:

java - Gradle 生成源

java - 运行hadoop时出现Classnotfound异常

java - 使用java正则表达式分别提取带小数的Alpha和Numeric包含String

java - 指定 main 方法接受的参数类型的目的是什么?

java - 将bean注入(inject)到默认构造函数中

java - JPA:合并和持久化上下文

java - 删除/复制/粘贴在 Eclipse Juno 中不起作用

java - 如何使用 POI 删除 ms-word 文档 (docx) 的某一特定页面?

java - Spring OAuth2 认证服务器 : a specific/oauth/token filter?

java - Spring 无法解析 servlet 中的 View