【问题标题】:package org.springframework.data.repository does not exist spring boot jpa包org.springframework.data.repository不存在spring boot jpa
【发布时间】:2017-09-11 13:57:32
【问题描述】:

我对 spring boot + jpa 有一个小问题。我已将依赖项添加到 POM.xml,我可以从 spring 工具套件正常运行它(作为 spring boot 应用程序运行)。但是当我从命令行“mvn spring-boot:run”运行时,它会抛出错误。

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building THA 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) > test-compile @ THA >>>
[WARNING] The POM for org.springframework:spring-jdbc:jar:4.3.7.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.jboss:jandex:jar:2.0.0.Final is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.springframework.data:spring-data-jpa:jar:1.11.1.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ THA ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ THA ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to D:\RondoWare\Programming\SpringBoot\workspace_3.8.3\THA\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/repository/ProductTypesRepository.java:[3,43] package org.springframework.data.repository does not exist
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/repository/ProductTypesRepository.java:[7,49] cannot find symbol
  symbol: class CrudRepository
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/controller/ProductTypeController.java:[29,39] cannot find symbol
  symbol:   method save(com.rondox.sb.th.model.ProductTypes)
  location: variable productTypesRepository of type com.rondox.sb.th.repository.ProductTypesRepository
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/controller/ProductTypeController.java:[36,46] cannot find symbol
  symbol:   method findAll()
  location: variable productTypesRepository of type com.rondox.sb.th.repository.ProductTypesRepository
[INFO] 4 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.795 s
[INFO] Finished at: 2017-04-15T19:37:52+07:00
[INFO] Final Memory: 26M/267M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project THA: Compilation failure: Compilation failure:
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/repository/ProductTypesRepository.java:[3,43] package org.springframework.data.repository does not exist
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/repository/ProductTypesRepository.java:[7,49] cannot find symbol
[ERROR]   symbol: class CrudRepository
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/controller/ProductTypeController.java:[29,39] cannot find symbol
[ERROR]   symbol:   method save(com.rondox.sb.th.model.ProductTypes)
[ERROR]   location: variable productTypesRepository of type com.rondox.sb.th.repository.ProductTypesRepository
[ERROR] /D:/RondoWare/Programming/SpringBoot/workspace_3.8.3/THA/src/main/java/com/rondox/sb/th/controller/ProductTypeController.java:[36,46] cannot find symbol
[ERROR]   symbol:   method findAll()
[ERROR]   location: variable productTypesRepository of type com.rondox.sb.th.repository.ProductTypesRepository
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

我的 pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<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.rondox.sb.th</groupId>
    <artifactId>THA</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>THA</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) -->

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

         <!---->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我的依赖树:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building THA 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.springframework:spring-jdbc:jar:4.3.7.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.jboss:jandex:jar:2.0.0.Final is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.springframework.data:spring-data-jpa:jar:1.11.1.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ THA ---
[INFO] com.rondox.sb.th:THA:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.5.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.5.2.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-context:jar:4.3.7.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.2.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.24:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.24:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.24:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.2.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.11:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.11:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.11:compile
[INFO] |  |  +- org.hibernate:hibernate-validator:jar:5.3.4.Final:compile
[INFO] |  |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  |  \- com.fasterxml:classmate:jar:1.3.3:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.7:compile
[INFO] |  |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.7:compile
[INFO] |  |  +- org.springframework:spring-web:jar:4.3.7.RELEASE:compile
[INFO] |  |  |  \- org.springframework:spring-beans:jar:4.3.7.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-webmvc:jar:4.3.7.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-expression:jar:4.3.7.RELEASE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO] |  |  +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO] |  |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO] |  |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.24:compile
[INFO] |  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO] |     \- org.codehaus.groovy:groovy:jar:2.4.9:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:4.3.7.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.9:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.2.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.11:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.11:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.7.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.11.1.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.7.RELEASE:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.41:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.5.2.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test:jar:1.5.2.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.2.RELEASE:test
[INFO]    +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO]    |  \- net.minidev:json-smart:jar:2.2.1:test
[INFO]    |     \- net.minidev:accessors-smart:jar:1.1:test
[INFO]    |        \- org.ow2.asm:asm:jar:5.0.3:test
[INFO]    +- junit:junit:jar:4.12:test
[INFO]    +- org.assertj:assertj-core:jar:2.6.0:test
[INFO]    +- org.mockito:mockito-core:jar:1.10.19:test
[INFO]    |  \- org.objenesis:objenesis:jar:2.1:test
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO]    +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO]    |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO]    +- org.springframework:spring-core:jar:4.3.7.RELEASE:compile
[INFO]    \- org.springframework:spring-test:jar:4.3.7.RELEASE:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.661 s
[INFO] Finished at: 2017-04-15T19:44:05+07:00
[INFO] Final Memory: 22M/309M
[INFO] ------------------------------------------------------------------------

当我从命令行运行应用程序时,我应该传递任何特殊参数吗? 这只是一个简单的应用程序,当我从 STS 运行时,该功能可以正常工作,但我只是想更好地了解 STS 和命令行在运行应用程序时是否有不同的参数。

【问题讨论】:

    标签: java spring maven spring-boot spring-data-jpa


    【解决方案1】:

    您必须删除 .m2 文件夹并更改依赖项的版本并重试更新 maven 项目。

    【讨论】:

    • 没有找到'org.springframework.data.repository.CrudRepository'的库
    • 基于操作系统的.m2目录位置 --> Windows: C:/Users//.m2 Linux: /home//.m2 Mac: /Users/ /.m2
    【解决方案2】:

    在我的情况下,我有两次依赖:

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

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

    删除第二个后,由于我在测试之外需要它,错误消失了。

    【讨论】:

      【解决方案3】:

      这一行是您问题的根本原因:

      [警告] org.springframework:spring-jdbc:jar:4.3.7.RELEASE 的 POM 无效,传递依赖(如果有)将不可用,请启用调试日志以获取更多详细信息

      我认为它来自您的 Maven 设置或命令行中的 java 版本。

      【讨论】:

      • 你能具体点吗?我的java版本“1.8.0_77”我也将java_home指向了那个jdk。已尝试使用该依赖错误进行谷歌搜索,但没有运气。
      • 您可以在完全调试模式下重新运行 > 使用 -X 开关重新运行 Maven 以启用完全调试日志记录。
      • 我已经使用 -X 运行,但我无法在此处更新该日志,因为它很长。好的,我发现了问题。
      • 对不起,我点击进入,它会发表​​我的评论。使用 -X 参数重新运行后,我可以看到更清晰的错误消息。它是由损坏的 pom 文件引起的。一旦我还发布了与没有类发现错误有关的问题,结果证明是由损坏的 jar 引起的。我的问题是如何验证我的本地 Maven 存储库是否处于完美状态?谢谢
      【解决方案4】:

      我使用带有 -X 参数的 maven 命令重新运行,因此它将打开调试日志记录。

      然后错误得到更清晰的错误信息

      [WARNING] The POM for org.springframework:spring-jdbc:jar:4.3.7.RELEASE is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model
      [FATAL] Non-parseable POM C:\Users\RondoDell\.m2\repository\org\springframework\spring-jdbc\4.3.7.RELEASE\spring-jdbc-4.3.7.RELEASE.pom: processing instruction can not have PITarget with reserveld xml name (position: END_TAG seen ...</dependencies>\n</project>\n<?xml ... @108:7)  @ line 108, column 7
      
      [WARNING] The POM for org.jboss:jandex:jar:2.0.0.Final is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model for org.jboss:jandex:2.0.0.Final
      [FATAL] Non-parseable POM C:\Users\RondoDell\.m2\repository\org\jboss\jboss-parent\12\jboss-parent-12.pom: only whitespace content allowed before start tag and not t (position: START_DOCUMENT seen t... @1:1)  @ C:\Users\RondoDell\.m2\repository\org\jboss\jboss-parent\12\jboss-parent-12.pom, line 1, column 1
      
      [WARNING] The POM for org.springframework.data:spring-data-jpa:jar:1.11.1.RELEASE is invalid, transitive dependencies (if any) will not be available: 1 problem was encountered while building the effective model for org.springframework.data:spring-data-jpa:1.11.1.RELEASE
      [FATAL] Non-parseable POM C:\Users\RondoDell\.m2\repository\org\springframework\data\build\spring-data-parent\1.9.1.RELEASE\spring-data-parent-1.9.1.RELEASE.pom: start tag not allowed in epilog but got s (position: END_TAG seen ...</pluginRepositories>\n\n</project>\n\t\t<s... @899:5)  @ C:\Users\RondoDell\.m2\repository\org\springframework\data\build\spring-data-parent\1.9.1.RELEASE\spring-data-parent-1.9.1.RELEASE.pom, line 899, column 5
      

      我删除了整个文件夹,使用命令行运行应用程序,它会重新下载所有需要的 pom 和 jar。应用程序现在可以从命令行正常运行了。

      【讨论】:

        【解决方案5】:

        您似乎下载了以下 pom 错误:

        [WARNING] The POM for org.springframework:spring-jdbc:jar:4.3.7.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
        [WARNING] The POM for org.jboss:jandex:jar:2.0.0.Final is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
        [WARNING] The POM for org.springframework.data:spring-data-jpa:jar:1.11.1.RELEASE is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
        

        我已经看到当 Maven 最终下载 HTML 错误页面而不是工件时会发生这种情况。您可以尝试在 ~/.m2/repository 删除本地 Maven 存储库,然后从命令行构建。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-02-03
          • 2021-11-07
          • 1970-01-01
          • 2021-06-22
          • 2018-01-10
          • 1970-01-01
          • 2018-08-06
          • 2018-06-18
          相关资源
          最近更新 更多