java - How to hide service classes and prevent @Autowire? -


i create framework has several default implementations interface.

question: how can hide default implementations of interface, users of framework forced use defaultservice interface eg injection @autowired defaultservice?

interface defaultservice { }  @component @async @conditionalonnotwebapplication public class myservice1 implements defaultservice {  }  @component @async @conditionalonwebapplication public class myservice2 implements defaultservice {  } 

the conditions on services ensure there 1 service wired in each environment.

as @m. deinum commented above making implementation services package private correct solution. not aware spring still sees classes, spring requires public access annotations.


one possible solution seems creating @configuration class implementations:

@configuration public class defaultserviceconfiguration {     @bean     @conditionalonnotwebapplication     public defaultservice getdefaultservice1() {         return new myservice1();     }      @bean     @conditionalonwebapplication     public defaultservice getdefaultservice2() {         return new myservice2();     } }  public interface defaultservice { }  @async protected class myservice1 { }  @async protected class myservice2 { } 

this way defaultservice interface visible framework users.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

Python Tornado package error when running server -