1

I followed the instructions outlined here to implement custom methods for my MongoDB Repository. However, none of the custom methods appear to be usable (findAllSeries and uploadSomeSeries do not seem to be found by spring). I have checked the naming

SeriesRepository:

@RepositoryRestResource(collectionResourceRel = "series", path = "series", excerptProjection = SeriesProjection.class)
public interface SeriesRepository extends MongoRepository<Series, String>, SeriesRepositoryCustom {

    List<Series> findByWinnerId(@Param("id") String id);
}

SeriesRepositoryCustom:

public interface SeriesRepositoryCustom {

    ResponseEntity<Void> createSeries(Series series);
}

SeriesRepositoryImpl:

public class SeriesRepositoryImpl implements SeriesRepositoryCustom {

    private final MongoOperations operations;

    @Autowired
    public SeriesRepositoryImpl(MongoOperations operations) {
        this.operations = operations;
    }

    @Override
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<Void> createSeries(@RequestBody Series series) {
        // ... implementation
    }
}

1 Answer 1

1

Got it working; via this answer, I had to implement a controller for my repository, and delegate the call to the method defined in the custom repository:

@RepositoryRestController
public class SeriesController {

    private final SeriesRepository repository;

    @Autowired
    public SeriesController(SeriesRepository repo) {
        repository = repo;
    }

    @RequestMapping(value = "/series", method = RequestMethod.POST)
    public ResponseEntity<Void> create(@RequestBody Series series) {
        return repository.createSeries(series);
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

why do you need SeriesRepository interface then in this example ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.