Bean/Component from another maven project not found.

huangapple 未分类评论46阅读模式
英文:

Bean/Component from another maven project not found

问题

我对 Spring Boot 框架还不熟悉,并且目前正在尝试在一个非常大的应用程序上学习。该应用程序由许多基于 mavenSpring Boot 项目组成,其结构如下:

  • Project1
    • com.x.y.z
    • com.x.y.w
  • Project2
    • com.x.y.a.b
    • com.x.y.a.c
  • Project3
    • com.x.y.d.e
    • com.x.y.d.f

所有项目都输出 jar,并且基于 com.x.y 包。Project1 包含了 main 函数。任何项目有可能依赖于其他项目(但不会出现循环依赖,因为 maven 不允许这样做)。然而,为了举例说明,假设 Project3 依赖于 Project1。项目是“带有依赖项构建”的。

问题

当我将任何 @Component 放入 Project1 时,它可以正常找到它们。然而,当我将 @Component 放入另一个项目(例如我们的示例中的 Project3),该项目依赖于主项目 Project1 时,它就无法找到它。

解决尝试

根据文档和 Google 的源代码建议,在 main 类中尝试使用 @ComponentScan("com.x.y"),但这并没有起作用。

此外,我尝试了 此帖子 上的两种解决方案,但它们也没有奏效。

真的非常感谢任何帮助。

英文:

I am new to the Spring Boot framework and currently trying to learn while working on a very large application. The application consists of many (maven based) Spring Boot projects and it has the following structure:

  • Project1
    • com.x.y.z
    • com.x.y.w
  • Project2
    • com.x.y.a.b
    • com.x.y.a.c
  • Project3
    • com.x.y.d.e
    • com.x.y.d.f

All the projects output jar and are based on com.x.y packages. Project1 contains the main function. There is a chance that any project is dependent on the other project (but not cyclic dependency since maven doesn't allow that). However, for the sake of example, assume Project3 is dependent on Project1. Projects are built with dependencies.

Question

When I place any @Component class inside Project1, it finds them without any problem. However, when I place a @Component inside another project (Project3 in our example) which is dependent on Project1 (the main project) it fails to find it.

Attempts to solve

As suggested in the documentation and Google source, I have tried using @ComponentScan("com.x.y") in the main class as well, but it didn't work out.

Also, I have tried both solutions on this post but they didn't work.

Any help will be really appreciated.

huangapple
  • 本文由 发表于 2020年4月6日 23:35:21
  • 转载请务必保留本文链接:https://java.coder-hub.com/61063414.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定