How to add custom method to Spring Data JPA

后端 未结 12 1893
盖世英雄少女心
盖世英雄少女心 2020-11-22 12:58

I am looking into Spring Data JPA. Consider the below example where I will get all the crud and finder functionality working by default and if I want to customize a finder t

12条回答
  •  北海茫月
    2020-11-22 13:34

    Im using the following code in order to access generated find methods from my custom implementation. Getting the implementation through the bean factory prevents circular bean creation problems.

    public class MyRepositoryImpl implements MyRepositoryExtensions, BeanFactoryAware {
    
        private BrandRepository myRepository;
    
        public MyBean findOne(int first, int second) {
            return myRepository.findOne(new Id(first, second));
        }
    
        public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
            myRepository = beanFactory.getBean(MyRepository.class);
        }
    }
    

提交回复
热议问题