Question

I am trying to create a custom query from the Spring guide : Accessing MongoDB Data with REST according to the Reference 4.4 Custom Implementations. But my custom method is not available from the repository's REST interface (/user/search).

(e.g. Browser is unable to find localhost:8080/user/search/GetByKidsAge?age=1)

Could someone help me to figured this out and give me some suggestions? Thanks a lot !!

Below is my code:

UserRepositoryCustom.java

public interface UserRepositoryCustom {     

    public List<User> GetByKidsAge(@Param("age") int age);
}

UserRepositoryImpl.java

public class UserRepositoryImpl implements UserRepositoryCustom {

    @Override
    public List<User> GetByKidsAge(int age) {

        return /*perform query*/;

    }
}

UserRepository.java

@RepositoryRestResource(collectionResourceRel = "user", path = "user")
public interface UserRepository extends MongoRepository<User, String>, UserRepositoryCustom {

        List<User> findByLastName(@Param("name") String name);  
}
Was it helpful?

Solution

This is by design. As soon as you start implementing a repository method manually we cannot know whether GET or POST is the right HTTP method as whether the execution is idempotent depends on how you implement it.

So the way to go would be implementing a custom controller and expose those methods using the adequate HTTP method. That said, there's a ticket in our tracker to provide means to define the way these methods should be exposed as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top