是否可以编写AOP注释?

问题描述 投票:0回答:2

所以,我得到2个注释A和B。他们俩都做我班上必要的事情:

public class MyClass{

    @A
    @B(value="key")
    public void method(){

    }
}

是否可以将第三个注释C定义为两者的组合?所以最后我会得到:

public class MyClass{

    @C(value="key")
    public void method(){

    }
}
java aop spring-aop
2个回答
0
投票

取决于您使用的库。例如春天做

@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
        @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
        @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {

    /**
     * Exclude specific auto-configuration classes such that they will never be applied.
     * @return the classes to exclude
     */
    @AliasFor(annotation = EnableAutoConfiguration.class)
    Class<?>[] exclude() default {};

使用这种方法,您将拥有:

@ A@B公共@interface C {@AliasFor(注释= B.class)字符串值();}


0
投票
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@A
@B
public @interface C {
    @AliasFor(annotation = B.class, attribute = "value")
    String value() default {};
}

让我知道是否可行。

© www.soinside.com 2019 - 2024. All rights reserved.