'Spring boot mongo repository custom implementation not working
hi i followed this instruction, and i have custom method implementation like this:
interface
interface ProfileMongoRepositoryCustom {
fun addCourse(id: String)
}
Implementation
class ProfileMongoRepositoryCustomImpl(
@Autowired val mongoOperations: MongoOperations,
) : ProfileMongoRepositoryCustom {
override fun addCourse(id: String) {
// some implementation
}
}
mongo repo
@Repository
interface ProfileMongoRepository : MongoRepository<Profile, String>, ProfileMongoRepositoryCustom {
fun findByEmail(email: String): Profile?
fun findByPhoneNumber(phoneNumber: String): Profile?
}
when i run the program, it shows an error:
No property addCourse found for type Profile!
it seems like the implementation is not read by the application because if i put the implementation in the same module and package with the interface it worked, my module structure is:
- -- project-app (main class)
- -- project-repo (this is where mongo repo and custom interface belong)
- -- project-repo-impl (this is where my custom implementaion belong)
Solution 1:[1]
Basically just remove "Mongo" on your repository custom interface name
Rename
ProfileMongoRepositoryCustom to ProfileRepositoryCustom
also
ProfileMongoRepositoryCustomImpl to ProfileRepositoryCustomImpl
Reference from https://docs.spring.io/spring-data/jpa/docs/1.6.0.RELEASE/reference/html/repositories.html (section: Adding custom behavior to single repositories)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rham |
