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
@conditionalannotation on base class (basebar) , framework consumers (fooone,footwo) should inherit base class.@conditionalannotation not inherited (as specified in javadoc) spring won't bother reading@conditionalannotation on base class. - use
@conditionalannotation meta-annotation on 1 of existing annotations (e.g.bar) applied class. in case, spring reading@conditionalannotationannotatedtypemetadatapassedconditionrepresents (meta-)annotations on annotation (bar) rather on class (fooone,footwo). not helpful me need read actual class annotations withincondition(reading metadata ofbarwithinbaz).
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
Post a Comment