0

I am writing a common component for team members.So I write an aspect with Spring-aop.Ideally,what others only need to do is defining an point-cut expression in .properties or others.But I find it is a bit difficult。

I have searched some information in stackoverflow,but i'm confused。

1、the value of @Pointcut:Attribute value must be constant,does this mean the value must be compile-time constant and can't use ${}? If it does,why? the Spring aop is based on LTW why the pointcut expression must be constant?

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Pointcut {
    String value() default "";

    String argNames() default "";
}

2、Can I read an external constant as the compile-time constant may like follow?

private static final String a;

static{
    String b = "xx";// read external file
    a = b;
}

@Pointcut(a) //not work
public void pointcut(){}

3、We use entire Annotation way without xml,So I can't let others define an another aop.xml,though I know it will work.

4、I have found a indirect way is

public abstract void pointcut();

and others to implement this abstract way,but not very elegant。

4、Should I implement it in a runtime-way? (But I have no idea)

5、Any suggestion will help me a lot!

wutingjia
  • 23
  • 7
  • just pass "aa" as value and let your aop code read in the value from your properties file – Stultuske Sep 02 '19 at 13:20
  • @Stultuske,the question is how to read a value from properties file and pass to @pointcut as a complie -time constant? Above is my try,but doesn't work – wutingjia Sep 02 '19 at 13:44
  • Writing pointcuts is nothing for noobs, you need to do what you are doing. So your expectation to take away all complexity from it IMO is misguided. What is wrong with defining pointcuts in an XML file? The rest of your aspects can still be annotation-style. Where is the difference from a properties file, other than the former being a way directly supported by Spring and the latter being unsupported? You can prepare a template XML file for your users and tell them where to fill in or overwrite the pointcut. An XML file can also be validated. Don't re-invent the wheel, keep it simple! – kriegaex Sep 03 '19 at 01:29
  • @wutingjia you can't. afaik you can't pass variables there. They have to be fixed values. – Stultuske Sep 03 '19 at 05:42

0 Answers0