Dynamically loadable and unloadable application modules in Java - how?

后端 未结 5 1995
醉酒成梦
醉酒成梦 2021-02-10 17:47

I\'m writing a server application which makes use of external modules. I would like to make them to be upgradeable without requiring server restart. How do I do that? I\'ve foun

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-10 18:36

    It seems like OSGi is exactly what you're asking for. It can be complex, but there are ways to deal with that. Some of the complexity can be mitigated by using SpringDM or something similar to handle the boilerplate tasks of registering and consuming services in the runtime. Annotation-driven service registration and dependency injection really reduces the amount of code that needs to be written.

    Another way to reduce complexity is to deploy the bulk of your application in a single bundle and only deploy the parts that need to be modular into their own bundles. This reduces your exposure to registering and using services from other bundles in the runtime as well as reducing the complexity of deployment. Code running within a bundle can use other code in the same bundle just as in a standard Java app - no need to interact with the OSGi runtime. The opposite of this approach is to break up your application into lots of discrete bundles that export well-defined services to other bundles in the system. While this is a very modular approach, it does come with extra complexity of managing all those bundles and more interaction with the OSGi runtime.

    I would suggest taking a look at the book "OSGi in Action" to get a sense of the issues and to see some decent samples.

提交回复
热议问题