Create a custom annotation to set a bunch of other annotation

Viewed 27

I have some repeated annotations in multiple classes. It looks like this -

@Configuration
@Data
@Slf4j
@ConfigurationProperties(prefix = "hello")
@PropertySource(value = "classpath:hello.yml", factory = YamlSourceFactory.class)`

I would like to combine and make a single Annotation class out of it. I want to write something like this -

@Configuration
@Data
@Documented
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@PropertySource(value = this.value, factory = this.factory)
@ConfigurationProperties(prefix = this.key)
public @interface CustomAnnotation {
    String name() default "";
    String[] key();
    String[] value();
    Class<? extends PropertySourceFactory> factory() default YamlSourceFactory.class;
}

so that in all my other files I can write only one line and it is taken care of by my Custom Annotation - @CustomAnnotation(key = "hello", value = "classpath:hello.yml")

Is this something possible to achieve ?

0 Answers
Related