JpaRepositoryFactoryBean<UserRepository, User, Integer> factory = new JpaRepositoryFactoryBean<UserRepository, User, Integer>();
factory.setEntityManager(entityManager);
factory.setBeanFactory(applicationContext);
factory.setRepositoryInterface(UserRepository.class);
factory.setCustomImplementation(new UserRepositoryImpl());
factory.setNamedQueries(namedQueries());
factory.setEvaluationContextProvider(evaluationContextProvider);
factory.afterPropertiesSet();
return factory.getObject();