旧式spring boot项目,在pom.xml和事务中包含spring boot starter数据jpa和spring tx?

vtwuwzda  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(308)

我使用的是一个旧式spring boot项目,它的pom.xml中列出了spring boot starter数据jpa依赖项,还有spring tx依赖项(用于事务管理),比如@enabletransactionmanagement注解等等。

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
      <version>${spring.boot.version}</version>
    </dependency>

  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${spring.version}</version>
    </dependency>

我的问题是-这种依赖是多余的吗?springbootstarterdatajpa是否默认地为您管理事务,这样注解和这个额外的“springtx”依赖关系就没有意义了?

gev0vcfq

gev0vcfq1#

是的,如果您不想显式声明springtx与springbootstarter数据jpa一起使用的版本,那么这是毫无意义的。
唯一需要显式声明可传递依赖项的情况是,其他依赖项依赖于该可传递依赖项版本。
例子:
a->b->c
d->c
依赖关系a需要b需要c,而依赖关系d也需要c。但是因为导入依赖项c的最短路径是依赖项d,所以它将从依赖项d导入版本。如果此导入的版本较低,并且由于需要不同的版本而与依赖项不兼容,则会发生错误。这时您需要用满足这两个依赖关系的版本显式声明依赖关系。

相关问题