我有一个 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/