开发者

Using Spring without exposing the dependencies to the Client app

开发者 https://www.devze.com 2023-04-02 16:54 出处:网络
I\'m writing a Java API for several clients, and would internally like to use Spring and it\'s several features, but I don\'t want to expose to the client my dependencies.

I'm writing a Java API for several clients, and would internally like to use Spring and it's several features, but I don't want to expose to the client my dependencies.

Is this possible?

So if my client uses a different version of spring would they be insulated from my internal Spring dependencies.

If so, would my spring dependencies be bundled internally inside my jar? As well as would a custom class loader be required by my client application?

I hav开发者_开发百科e heard you can use this through OSGI bundles, but I'm wondering if this would satisfy my requirement.

The clients of my API wouldn't be OSGI enabled or we have no current environment that utilizes OSGI bundles.


It is not really feasible, or desirable to do so. Why would you want to "hide" the dependencies? Would you also want to hide a dependency on whatever logging package you may be using (for example)?

If you have the dependencies in your implementation, then they are best published as it will cause a lot less grief on the part of users of your API since they will know what conflicts may exist before they even attempt to use your code.

Don't forget, your users are actually developers and I am sure that they would rather be aware of any landmines or requirements up front.

Edit - Regarding OSGi:

OSGi will definitely take care of your conflicting dependencies issues, but it also would rely on deploying in an OSGi environment, which you haven't mentioned is the case for your clients. In addition, it is still not recommended to "hide" those dependencies in a bundle. The very nature of OSGi allows those conficting depencies to cooexist in the same application.

0

精彩评论

暂无评论...
验证码 换一张
取 消