Javax.persistence 和 hibernate-core maven 依赖项不适用于 spring-boot-starter-data-jpa [英] Javax.persistence and hibernate-core maven dependency not working with spring-boot-starter-data-jpa

查看:94
本文介绍了Javax.persistence 和 hibernate-core maven 依赖项不适用于 spring-boot-starter-data-jpa的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从 Bintray 和 JCenter 日落之后,我面临着 CI/CD 管道构建的问题.我发现了这个问题,并在 stackoverflow 用户的帮助下通过添加额外的存储库来修复它.

Since the Bintray and JCenter sunset, I am facing issue with CI/CD Pipeline build. I identified the issue and fixed it with the help of stackoverflow user by including additional repositories.

现在在添加新存储库后,我面临着 spring-data-jpa 依赖项的问题(尤其是 hibernate-core 和持久性 api 不起作用,我看到编译时错误).在运行 mvn clean install 命令时,我收到错误 package javax.persistence not found.项目结构是多模块,父模块和许多子模块如下 -

Now after adding new repositories, I am facing issue with dependencies for spring-data-jpa (especially hibernate-core and persistence api is not working and I see compile time error). While running mvn clean install command, I got the error package javax.persistence not found. Project structure is multi-module with a parent and many Child module as below -

父 pom

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>sfv</name>
    <url>http://maven.apache.org</url>
    <modules>
        <module>mysql-db</module>
        <module>demo-util</module>

    </modules>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <spring.boot.version>1.3.3.RELEASE</spring.boot.version>
        <spring.version>4.2.5.RELEASE</spring.version>
        <aws.version>1.9.22</aws.version>
        <searchbox.version>2.0.0</searchbox.version>
        <mysql.version>5.1.38</mysql.version>
        <ehcache.version>2.10.1</ehcache.version>
        <commons.net.version>2.0</commons.net.version>
        <thumbnailator.version>0.4.8</thumbnailator.version>
        <google.api.version>v4-rev9-1.22.0</google.api.version>
        <gson.client.version>1.21.0</gson.client.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Brixton.RELEASE</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Brixton.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>

    </dependencyManagement>

    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray</name>
            <url>https://repo1.maven.org/maven2</url>
        </repository>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-repo</id>
            <name>Spring Repository</name>
            <url>https://repo.spring.io/release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>maven-central</id>
            <name>Maven Central</name>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.4</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>com.sfv.App</mainClass>
                    <arguments>
                        <argument>argument1</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jfrog.buildinfo</groupId>
                <artifactId>artifactory-maven-plugin</artifactId>
                <inherited>false</inherited>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.3.1</version>

                <configuration>
                    <archive>
                        <addMavenDescriptor>false</addMavenDescriptor>
                    </archive>
                </configuration>
            </plugin>
        </plugins>

    </build>
</project>

mysql-db pom -

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.demo.db.mysql</groupId>
    <artifactId>mysql-db</artifactId>
    <packaging>jar</packaging>

    <name>mysql-db</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>com.demo</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </dependency>
        
    </dependencies>

</project>

utilmysql 项目的所有依赖开始以某种方式破坏.我试图包括丢失的版本,但似乎在我修复一个版本时,列表不断增加.例如,为了修复 javax.persistence 错误,我包含以下两个依赖项 -

All dependency for util and mysql project started breaking somehow. I tried to include missing versions but seems as I fix one, the list keep on growing. For example, to fix javax.persistence error I include below two dependency -

<dependency>
                <groupId>javax.persistence</groupId>
                <artifactId>javax.persistence-api</artifactId>
  
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>

            </dependency>

但是,在 util 项目中,我遇到了 slf4j 依赖项错误.这些依赖以前是由 spring-boot-starter-data-jpa 提供的,但自从离开 Bintray 后就不再工作了.

But further, in the util project, I got slf4j dependency error. These dependency previous was provided by spring-boot-starter-data-jpa, but not working anymore since moving away from Bintray.

推荐答案

幸运的是,这个问题与依赖管理无关,而是与工件服务器有关.我正在管理内部工件服务器,它是存储库的主要来源.

Fortunately, this issue was not related to dependency management but artifactory server. I am managing internal artifactory server which is primary source of repositories.

在使用 mvn clean install 命令时,错误会误导依赖问题,但实际问题是 Artifactory 服务器存储失败,导致无法解决的依赖问题.由于下载操作也受到影响,Artifactory 服务器上的存储空间已满.为了解决这个错误,我们向服务器添加了额外的卷,之后它开始正常工作.

While using mvn clean install command the error was misleading to dependency issue but the actual issue was Artifactory Server Storage failure which lead to unresolved dependency. Storage space was full on Artifactory server due to which download operations were also impacted. To resolve this error, we added extra volume to the server and it started working fine there after.

这篇关于Javax.persistence 和 hibernate-core maven 依赖项不适用于 spring-boot-starter-data-jpa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆