无法导入Spring RepositoryRestResource

Vir*_*tan 9 rest spring spring-mvc spring-data spring-boot

我试图通过Spring实现基于REST的MongoDB服务,但我遇到了一些麻烦.我无法导入某个库.

我在课堂上有这个:

package main;

import java.util.List;

import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends MongoRepository<Person, String> {

    List<Person> findByLastName(@Param("name") String name);

}
Run Code Online (Sandbox Code Playgroud)

但由于import org.springframework.data.rest.core.annotation.RepositoryRestResource; 某种原因,它不起作用,并给我错误:The import org.springframework.data.rest cannot be resolved

这是我的maven pom.xml:

<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>UserRegistrationServices</groupId>
    <artifactId>UserRegistrationServices</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.5.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <!-- Get the dependencies of a web application -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

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

    <build>
        <plugins>
            <!-- Spring Boot Maven Support -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

此外,我直接遵循本指南:http://spring.io/guides/gs/accessing-mongodb-data-rest/

怎么解决这个问题?谢谢

Jav*_*ine 14

编辑你的pom.xml ....并在里面添加这些行<dependencies></dependencies>...

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
        <version>1.2.5.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)