4

I have Spring Data repositories exposed to REST with @RepositoryRestMvcConfiguration. The problem is that custom methods seems not to be exposed by default, nor I see annotations to configure that. My code:

@RepositoryRestResource(path = "users", collectionResourceRel = "users")
public interface UserRepository extends JpaRepository<User, Integer> {

@Modifying
@Query("update User u set u.password = ?3 where u.login = ?1 and u.password = ?2")
int changePassword(String login, String oldPassword, String newPassword);

User findUserByEmail(String email);

User findUserByLogin(String login);

}

I need REST URL for changePassword, preferably with the way to configure it somehow like in controller:

@Modifying
@Query("update User u set u.password = ?3 where u.login = ?1 and u.password = ?2")
@RepositoryRestRequestMapping(value={"/changepwd"},  method = RequestMethod.POST)
int changePassword(String login, String oldPassword, String newPassword);

Well, it is understandable that repository class is not aware of REST and probably this is not right place for web-related annotation. But some way to configure it must exist . It is too bad to add controllers for such needs - actually a few operations against the same entity class that just does not exactly fit to CRUD concept.

I am new to Spring Data and might miss something. Will appreciate very much if this is already supported - please adivse.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
dkane
  • 303
  • 2
  • 15
  • I believe this is a duplicate of http://stackoverflow.com/questions/21116539/custom-jpa-repository-method-published-by-spring-data-rest – JBCP Oct 23 '14 at 18:27

0 Answers0