在学习SpringBoot的 JPA时候增加一个实体类的时候发现import包的时候一直报错。

由import javax.persistence.*;引用引发问题的思考(SpringBoot)

对比一下,发现自己的项目里面是少了 spring-boot-starter-data-jpa.jar包的引用。但是发现即使在Maven里面加入了spring-boot-starter-data-jpa包还是无法排除错误。

最后对比了一下,发现官方的代码案例里面spring-boot-starter-data-jpa包在Maven Project里面看是既能看到spring-boot-starter-data-jpa包的引用,也能看到spring-boot-starter-data-jpa包的前置引用。但是自己的项目里面只能看到spring-boot-starter-data-jpa.jar包的引用,看不见spring-boot-starter-data-jpa.jar包的前置引用。

由import javax.persistence.*;引用引发问题的思考(SpringBoot)

最后面对比了一下发现官方案例代码里面POM文件尾部包含了下述代码自己的项目里面是没有的。

由import javax.persistence.*;引用引发问题的思考(SpringBoot)

 

<repositories>
        <repository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
        <repository>
            <id>org.jboss.repository.releases</id>
            <name>JBoss Maven Release Repository</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

 

 在自己项目的POM文件中加入上述代码,发现Maven重新引用了好多新的Jar包过来,错误提示自动就消失了。

该段代码的工作原理待分析。

 

相关文章:

  • 2022-12-23
  • 2022-02-28
  • 2018-05-14
  • 2021-11-06
  • 2022-03-08
  • 2021-11-24
  • 2022-02-02
  • 2021-07-31
猜你喜欢
  • 2021-12-20
  • 2021-07-31
  • 2021-06-13
  • 2021-07-19
  • 2021-11-27
  • 2021-09-30
相关资源
相似解决方案