【发布时间】:2021-11-07 06:15:24
【问题描述】:
想要创建包含多个注解的注解,但想要使其更具可配置性,以便在所有场景中更可行
@SpringBootApplication
@ServletComponentScan(basepackages="com.example.commons.traceability")
@ComponentScan(basePackages={
"com.example.commons.security",
"com.example.commons.restTemplate",
"com.example.commons.logging",
})
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Microservice{
String[] scanBasePackages() default {};
}
我想在 Spring Application 文件中使用这个应用程序,但也想让 componentScan 更具可配置性,以便除了默认包之外,其他包也可以包含在组件扫描中
@Microservice(scanBasePackages={"com.example.myproject"})
public class MySpringApplciation{
public static void main (final String[] args){
// some code
}
}
如果我传递了 scanBasePackages 的值,那么在上面的代码中,这些包也应该包含在组件扫描中。
有没有办法在自定义注释中包含 componentScan 内的 scanBasePackages 的值?
【问题讨论】:
标签: java spring annotations spring-annotations