环境:SpringBoot2.3.8.RELEASE+JDK1.8本文教大家如何在SpringBoot环境下让自定义注解使用${xxx}表达式。相关依赖>runtime自定义注解@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.METHOD)@Documentedpublic@interfaceManufactur{Stringvalue()default"";//厂商编号}AOP需要AOP在执行method设备解析方法上的注解,获取占位符对应的值)")privatevoidinfo(){}@Before("info()")publicvoidexecBefore(JoinPointjp){MethodSignaturesign=(MethodSignature)jp.getSignature();Methodmethod=sign.getMethod();Manufacturmanu=method.getAnnotation(Manufactur.class);字符串值=人u.值e();logger.info("获取注释值:{}",value);BusinessService.code.set(this.environment.resolvePlaceholders(value));}@OverridepublicvoidsetEnvironment(Environmentenvironment){this.environment=environment;}}该类实现了EnvironmentAware获取Environment对象,可以通过该类的resolvePlaceholders方法获取当前环境中的所有相关配置信息,解析占位符对应的内容值。在服务中使用@ServicepublicclassBusinessService{publicstaticThreadLocal
