Java 包org.springframework.data.repository不存在spring boot jpa

Java 包org.springframework.data.repository不存在spring boot jpa,java,spring,maven,spring-boot,spring-data-jpa,Java,Spring,Maven,Spring Boot,Spring Data Jpa,我对spring boot+jpa有一个lil问题。我已经将依赖项添加到POM.xml中,我可以从spring工具套件(作为spring启动应用程序运行)正常运行它。但当我从命令行“mvn spring boot:run”运行时,它会抛出错误 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Bu

我对spring boot+jpa有一个lil问题。我已经将依赖项添加到POM.xml中,我可以从spring工具套件(作为spring启动应用程序运行)正常运行它。但当我从命令行“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
my 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>
当我从命令行运行应用程序时,是否应该传递任何特殊参数?
这只是一个简单的应用程序,当我从STS运行时,函数可以像我预期的那样工作,但是我只是想更好地理解在运行应用程序时STS&命令行是否有不同的参数

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

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


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

我使用带-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
[警告]org.springframework:spring jdbc:jar:4.3.7.RELEASE的POM无效,传递依赖项(如果有)将不可用:构建有效模型时遇到1个问题

[致命]不可解析的POM C:\Users\RondoDell\.m2\repository\org\springframework\spring jdbc\4.3.7.RELEASE\spring-jdbc-4.3.7.RELEASE.POM:processing指令不能具有保留xml名称的PITarget(位置:END\u标记已看到…\n\n看起来您下载的以下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存储库,然后从命令行生成。

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

在我的例子中我有两次依赖关系:

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

org.springframework.boot
spring引导启动器数据jpa


org.springframework.boot
spring引导启动器数据jpa
测试

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

你可以是mo特定的吗?我的java版本“1.8.0\u 77”我也将java_指向该jdk。我尝试过用谷歌搜索该依赖项错误,但没有成功。您可以使用-X开关重新运行full Debug mode>re run Maven以启用完全调试日志记录。我使用-X运行过,但我无法在此处更新该日志,因为它太长了。好的,我已经发现了问题。很抱歉,我单击enter,它将显示t我的评论。使用-X参数重新运行后,我可以看到一条更清晰的错误消息。这是由损坏的pom文件引起的。有一次,我还发布了一个问题,该问题与未发现类相关,该错误是由损坏的jar引起的。我的问题是,我如何验证我的本地maven存储库是否处于完美状态?感谢为“org.springfr”找到的库amework.data.repository.CrudRepository'
<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>