3

I'm using spring-boot-starter-data-rest and spring-boot-starter-data-mongodb as per the tutorial given here. I'm attempting to create a custom method for a MongoRepository, but having no success.

I've followed the steps given for adding custom behavior to single repositories, but I'm getting a 404 error when I attempt to access the custom method. Hitting the parent endpoint also shows no sign of the method, but I didn't expect it to do that.

Help me, please! What am I doing wrong!?

My code is as follows:

Application.java

@SpringBootApplication
public class Application extends AbstractMongoConfiguration {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

ItemRepositoryCustom.java

public interface ItemRepositoryCustom {
    void customMethod();
}

ItemRepositoryImpl.java

public class ItemRepositoryImpl {
    @Override
    public void customMethod() {
        ...
    }
}

ItemRepository.java

@RepositoryRestResource(collectionResourceRel="items", path="items")
public interface ItemRepository extends MongoRepository<Item, String>, ItemRepositoryCustom {
    List<Item> findByName(@Param("name") String name);
}
ArunM
  • 2,274
  • 3
  • 25
  • 47
MJ.
  • 1,269
  • 4
  • 12
  • 24
  • 1
    Custom Repository are not allowed in Spring Data Rest as per http://stackoverflow.com/questions/21116539/custom-jpa-repository-method-published-by-spring-data-rest. – ArunM Jun 04 '15 at 06:48
  • Already asked and answered: http://stackoverflow.com/a/25217113/5873923 - can someone mark this as a duplicate? – Marc Tarin Apr 22 '16 at 15:48

1 Answers1

0

Change your custom implementation class name from ItemRepositoryImpl to ItemRepositoryCustomImpl.

I followed spring documentation here.

Cheers!

kalehmann
  • 4,821
  • 6
  • 26
  • 36