java - How do I avoid for my framework consumers to have to put the Spring @Conditional annotation? -


i have framework objects framework annotation have considered have @conditional spring annotation work. rather abstract spring , simplify api consumers. example, consumer has classes fooone , footwo have annotation bar - want fooone , footwo automatically considered have @conditional(baz.class) annotation.

@bar("blahblah") @conditional(baz.class) // want implicit public class fooone {     // stuff }  @bar("blahblahblah") @conditional(baz.class) // want implicit public class footwo {     // stuff }  @retention(retentionpolicy.runtime) @inherited @configuration //@conditional(baz.class) - see second bullet below public @interface bar {     // stuff }  public class baz implements condition {     @override     public boolean matches(conditioncontext conditioncontext, annotatedtypemetadata annotatedtypemetadata) {         map<string,object> barmetadata = annotatedtypemetadata.getannotationattributes("bar");         // stuff         return something;     } } 

i had 2 ideas:

  • add @conditional annotation on base class (basebar) , framework consumers (fooone, footwo) should inherit base class. @conditional annotation not inherited (as specified in javadoc) spring won't bother reading @conditional annotation on base class.
  • use @conditional annotation meta-annotation on 1 of existing annotations (e.g. bar) applied class. in case, spring reading @conditional annotation annotatedtypemetadata passed condition represents (meta-)annotations on annotation (bar) rather on class (fooone, footwo). not helpful me need read actual class annotations within condition (reading metadata of bar within baz).

is there way around - other options available? example, there way access class annotations when @conditional used meta-annotation? or there way wrap @conditional make inherited? or way extend spring's @conditional-resolving code make more suitable use-case?


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -