【发布时间】:2020-03-14 04:23:50
【问题描述】:
我正在制作一个与 Spring Boot 一起使用的库。这个库定义了一些可以在方法中使用的注解。
如何(在运行时)找到正在使用该库的应用程序包?
我需要这个来扫描带注释的方法。
【问题讨论】:
-
你想创建 spring boot 启动器吗?
-
你可以像 Spring 一样扫描 @ComponentScan(basePackages = "package.name") 下的所有类。或者提供另一个自定义注释添加到主类中,使用该库的客户端应用程序可以使用您的自定义注释来声明要扫描的包。
-
@codeMan 仅在必要时才能工作
-
@RajeshDwivedi 第一个怎么办?
-
Spring 已经有了这个代码。请通过 org.springframework.boot.autoconfigure.domain.EntityScanPackages 类。它可以提供更好的了解 spring 是如何处理它的。您可以在同一行上对齐您的实现。 github.com/spring-projects/spring-boot/blob/master/…
标签: spring-boot modularity component-scan