Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring REST Data

I'm trying to expose Spring REST Data using a 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);

}

By using the dependencies found in the example, I'm unable to 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've 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 compiles, however the execution fails with:

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 ?

like image 933
user2824073 Avatar asked Sep 15 '26 12:09

user2824073


1 Answers

You should be able to remove the additional dependency as Spring Boot's REST starter already pulls in all dependencies in the correct versions.

Spring Boot 1.2.3 refers to the Spring Data train Evans in its second service release. This boils down to Spring Data REST 2.2.2. If you want to upgrade to a newer release train (e.g. Fowler), change the value of the spring-data-releasetrain.version property to Fowler-GA. That will then upgrade Spring Data REST to 2.3.0 and also make sure you get all required dependencies in matching versions.

like image 146
Oliver Drotbohm Avatar answered Sep 18 '26 02:09

Oliver Drotbohm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!