Create reusable modules

I am writing a large Java Red5 application for the web. Red5 is an alternative to Flash Media Server, based on java and written using the spring framework.

I want to have many versions of my application online, each of which has different types of behavior and different classes that are enabled or disabled.

I am looking for a way to convert my code into module-based code that will allow me to remove / add modules / functions from the main application.

I know about OSGI http://www.springsource.org/osgi , but he says that he needs a SpringSource dns server, and I have no idea how it will work together in red5, and it seems very difficult to understand.

I do not have a good knowledge of the spring structure as a whole, I work with it related to db and this. red5 uses it more widely.

so can anyone understand the meaning of this information? is there anything that can be done to split my code into modules?

All information regarding this issue would be greatly appreciated.

+7
source share
1 answer

My preferred method of dealing with this situation is dependency injection (DI). Spring has a built-in DI function for which the tutorial is easy to find on the Internet . However, Spring DI is not as good for many reasons as Guice provides, which I would highly recommend. (The main advantage of Guice over Spring DI, in my opinion, is type safety.)

DI is basically a mechanism for replacing class implementations at runtime. Instead of hard code dependencies in classes (for example, if you have a class building other classes, for example), you encode them so that their dependent classes are passed to them in their constructors. The DI structure will then pass the correct instances at runtime as configured. Spring configuration can be done using annotations or an XML file; Guice uses a subclass of com.google.inject.AbstractModule .

Thus, you can use different configuration files for different instances of your application and provide them with different sets of functions for activation or, indeed, different implementations of the same function. If you configured the application to use this technique, the only thing needed for different instances is a single configuration file.

+4
source

All Articles