【问题标题】:Is it possible to add the all scan base packages into spring.factories file in Spring Boot?是否可以将所有扫描基础包添加到 Spring Boot 中的 spring.factories 文件中?
【发布时间】:2018-10-17 04:34:25
【问题描述】:

我有不止一个 spring boot 模块。其他模块之间存在依赖关系。每个项目都有一个模块。在这里我不想使用@CamponentScan("com.myapp.register,com.module.admin")@SpringBootApplication(scanBasePackages={"com.myapp.register","com.module.admin"}) 在我的项目中。因为如果将来我们想再添加一个基础包,我不想采用上述方法。

如果有任何其他方式可以在我们的包中添加基础包。 我认为 spring.factories 更适合这个。我的意思是这也和属性文件一样。 spring.factories 是配置自动配置。但我不知道如何将基础包添加到该文件中。

我在几个教程中看到了一些示例,它们仅提供配置类。

我这样做了,但我们仍然需要在我的代码中使用@ComponentScan。我不想要这种方法。

我想将所有基础包添加到 spring.factories 是否可以?如果可能,请提供解决方案和示例方式。

【问题讨论】:

    标签: spring spring-boot spring-data spring-boot-actuator spring-boot-admin


    【解决方案1】:

    我不认为这是spring.factories 文件的目的。如果您想开发具有自动配置功能的模块,那么您可以这样做。为此,您可以使用以下教程 Spring Boot Auto Configuration 1Spring Boot Auto Configuration 2

    在您的情况下,您可以使用类似的包命名约定,例如 com.myapp.module,也可以使用 @ComponentScan("com.myapp.module.*")

    【讨论】:

      猜你喜欢
      • 2018-07-22
      • 1970-01-01
      • 2014-10-11
      • 2010-10-12
      • 2023-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多