java - How can I decouple a non-Spring client from the configuration of a Spring-based jar? -


i have limited experience spring working likes it. we've built set of packages use spring heavily , need provide access layer exposes functionality clients may not use spring.

my primary goal clients of access layer should not required configure spring in order use it. spring on deployment classpath. in ideal world, client build against access layer package , deploy without knowing spring being used. possible? (no, using remote service not option.)

as don't want have write load of new code wires application same way spring it, possible hide of behind sort of "facade" class give client?

for example, had spring context sets servicea , serviceb (these services client wants access)

i write classes this...

public interface clientservicefacade {     servicea getservicea();      serviceb getserviceb();      void shutdown(); }  public class clientservicefacadefactory {     public static clientservicefacade create() {         return new clientservicefacadeimpl();     } }  public class clientservicefacadeimpl implements clientservicefacade {     private static final context_location = "classpath:spring/context.xml";      private classpathxmlapplicationcontext context;      public clientservicefacadeimpl() {         context = new classpathxmlapplicationcontext(context_location);     }      @override     public servicea getservicea() {         return context.getbean(servicea.class);     }      @override     public serviceb getserviceb() {         return context.getbean(serviceb.class);     }      @override     public void shutdown() {         context.close();     } } 

your clients still have include spring jar dependency, (apart form that) have no idea spring being used in background.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -