有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

spring boot应用程序中的java多个spring数据jpa模块(非spring boot)依赖关系?

我们正在构建独立的、可重用的spring数据jpa模块,无需spring引导。让我们称之为db模块。这些模块将导入另一个spring boot应用程序。在db模块中,我们包括

<dependency>
   <groupId>org.springframework.data</groupId>
   <artifactId>spring-data-jpa</artifactId>
   <scope>provided</scope>
</dependency>

然而,在主要的spring引导中,我们已经包括了

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

db模块中的所有spring依赖项都在spring主引导应用程序提供的范围内,并且预期在运行时出现。这样做对吗

另外,每个db模块是否都有自己的db连接属性文件,或者它们是否回复主spring引导应用程序。所有数据库模块都连接到同一个数据库。这些模块代表应用程序中的不同域


共 (1) 个答案

  1. # 1 楼答案

    不,使用<scope>provided</scope>是不正确的

    正如专家所说:

    provided
    This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. A dependency with this scope is added to the classpath used for compilation and test, but not the runtime classpath. It is not transitive.

    换句话说,它是由运行时在部署程序集之外“提供”的

    如果在打包用于部署的代码时必须包含依赖项,那么您肯定不希望它对您来说是provided

    请记住,您的库需要告诉依赖于您的库的构建系统,它需要包括哪些其他库以及您的库。这就是可传递依赖项的全部目的,因此,如果不将spring-data-jpa作为可传递依赖项,那么您就错了