简体   繁体   中英

Exception when doing custom method in JPA Repository

public class UserRepositoryImpl implements UserRepositoryCustom<User, Long> {

    @Override
    public void customMethod(User user) {

    }
}

public interface UserRepositoryCustom<T, ID extends Serializable> {

    void customMethod(User user);
}

@RepositoryRestResource
public interface UserRepository extends JpaRepository<User, Long>,
            UserRepositoryCustom<User, Long> {
}

Why do I get this exception

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

Spring implements the method you have written in the UserRepository interface while startup. In repositories that extends JpaRepository you are not allowed to write any custom method that does not compliant with Spring data JPA. So while spring takes the method list of the UserRepository it also gets the your custom method which is not as per the syntax of Spring JPA Repository. So it throws exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM