0

I have a interface extened by ReactiveCrudRepository as follows. Since I needed to write a aggregate query I created another interface and implemented the custom method there.

public interface MyNiceRepository extends ReactiveCrudRepository<MyNiceObject, String>, MyNiceCustomRepository {

Mono<MyNiceObject> findOneByName(String name);
}

MyNiceCustomRepository

public interface MyNiceCustomRepository {

Flux<MyNiceObject> customMethod(CustomObject request);

}

I get the following exception, it seems like spring is trying to parse the custom method in the second interface as well.

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property customMethod found for type MyNiceObject!

How this should be done

Susitha Ravinda Senarath
  • 1,648
  • 2
  • 27
  • 49
  • Looks like Spring is trying to autogenerate a class that implements that interface because it extends `ReactiveCrudRepository`. You need to either not make `MyNiceRepository` extend both the interfaces or use annotations to help Spring understand how to implement `customMethod` such as `@Query` or `@NativeQuery`. I don't believe this is a way to make Spring just ignore it because it has to implement something for that method to make a class that implements it. – DCTID Jan 11 '20 at 17:25
  • @DCTID this is how should be done with MongoRepository at lest. ( https://blog.marcnuri.com/spring-data-mongodb-custom-repository-implementation/) They might have change something in later releases. FYI MyNiceCustomRepository is implemented by a MyNiceRepositoryCustomImpl and it has custom query with aggregations an all. As you said I just need Spring to stop autogenerate my custom method. – Susitha Ravinda Senarath Jan 12 '20 at 11:48
  • 1
    Your example is correct, the interface `BookRepository` extends `MongoRepository` and Spring autogenerates the class. Then interface `BookRepositoryCustom` is not autogenerated but actually implemented by the author as `BookRepositoryImpl`. In your case you are trying to put together. You can't have a single interface that extends both of the other interfaces Spring just doesn't know how to implement `customMethod`. – DCTID Jan 14 '20 at 02:54
  • https://stackoverflow.com/questions/11880924/how-to-add-custom-method-to-spring-data-jpa – R.G Jan 14 '20 at 10:36

0 Answers0