Spring Data REST

I'm trying to expose Spring REST data using the demo application found in the documentation:

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

}

      

Using the dependencies found in the example, I cannot find the 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>

      

Following Netbeans advice, I added the following dependency:

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

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

      

Now the code is compiled, but the execution fails:

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)

      

Any idea how to solve it?

+3


source to share


1 answer


You should be able to remove the additional dependency as Spring REST starter runs on all dependencies in the correct versions.



Spring Boot 1.2.3 refers to Spring Data train Evans in the second release of the service. This boils down to Spring Data REST 2.2.2. If you want to go to a new transfer course (such as Fowler), change the property value spring-data-releasetrain.version

to Fowler-GA

. Then Spring Data REST will be updated to 2.3.0 and also make sure you get all required dependencies in the appropriate versions.

+3


source







All Articles