【问题标题】:How to autowire datasource from dependent spring boot app in another spring boot jar project?如何在另一个 Spring Boot jar 项目中从依赖的 Spring Boot 应用程序中自动连接数据源?
【发布时间】:2021-02-04 10:50:52
【问题描述】:

我有 Spring Boot Web 应用程序,我们将其命名为 A 和 jar spring boot 项目,我们将其命名为 B。Spring boot 应用程序 A 的 pom 文件中存在对 jar B 的依赖关系。数据源在应用程序 A 中定义。现在的问题是如下:是否有可能从 jar B 中的应用程序 A 自动装配 DataSource? 当我尝试自动装配时,会出现警告:“无法自动装配。找不到“数据源”类型的 bean”。是否有可能在 jar B 中指向 spring boot,以从依赖应用程序自动连接 DataSource?任何建议都会非常有帮助。非常感谢!

【问题讨论】:

    标签: spring spring-boot dependency-injection dependencies javabeans


    【解决方案1】:

    您只需添加@ComponentScan 注释并在第二个应用程序中包含Spring 要扫描的第一个应用程序的包即可。

    这是您应该在第二个应用程序中执行的操作:

    @ComponentScan("foo.bar")
    @SpringBootApplication
    

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 2017-02-26
      相关资源
      最近更新 更多