Spring REST Data

3

我正在尝试使用文档中找到的演示应用程序暴露Spring REST数据:

package hello;

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);

}

通过使用示例中找到的依赖项,我无法找到RepositoryRestResource:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.3.RELEASE</version>
    </parent>

    <dependencies>
        <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>

根据Netbeans的建议,我添加了以下依赖项:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-rest-core</artifactId>

    <type>jar</type>
    <version>2.3.0.RELEASE</version>
</dependency>

现在代码编译成功,但是执行时出现以下错误:
Caused by: java.lang.NoClassDefFoundError: org/springframework/data/rest/core/invoke/RepositoryInvokerFactory
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
    at java.lang.Class.getDeclaredMethods(Class.java:1855)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:571)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:488)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:474)
    at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:534)

有什么想法来解决这个问题吗?
1个回答

3

由于Spring Boot的REST starter已经正确地拉取了所有依赖关系的正确版本,因此您应该能够删除额外的依赖项。

Spring Boot 1.2.3在第二个服务发布中使用Spring Data train Evans。这归结为Spring Data REST 2.2.2。如果您想升级到更新的发布系列(例如Fowler),请将spring-data-releasetrain.version属性的值更改为Fowler-GA。这将升级Spring Data REST到2.3.0,并确保您获得所有所需的匹配版本的依赖项。


谢谢,看起来是Netbeans环境的问题。使用Maven shell编译后就可以了。 - user2824073

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接