-1

Is it possible to move spring data repo Implementation to different folder (not same or sub folder of original inteface)? If I have interface and implementation in same folder all works fine. If I move it from e.g com.app.domain.repo to com.app.infrastr.repo, I get Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property methodName found for type RepoInterfaceName.

UPDATE

import com.app.domain.repo

public interface ARepo extends ElasticsearchRepository<A, String>, CustomizedARepo {
}

public interface CustomizedARepo {
    List<A> makeSearch(int x);
}

import com.app.infrastr.repo

public class CustomizedARepoImpl implements CustomizedARepo {

    private ElasticsearchTemplate elasticsearchTemplate;

    public CustomizedARepoImpl(ElasticsearchTemplate elasticsearchTemplate) {
        this.elasticsearchTemplate = elasticsearchTemplate;
    }

    @Override
    public List<A> makeSearch(int x){ return null; }
}

And configuration class is

@Configuration
@EnableElasticsearchRepositories(basePackages = {"com.app.domain.repo", "com.app.infrastr.repo"})
public class Config{}

Error is:

Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property makeSearch found for type ARepo

If I move CustomizedARepoImpl to com.app.domain.repo all works OK.

Bojan Vukasovic
  • 2,054
  • 22
  • 43
  • Please provide relevant code here to help people answer. There are many possibilities here. My guess is that you have a custom entityManagerFactory() bean that points to the specific package. – Brian Dec 01 '17 at 12:30
  • I updated the question. – Bojan Vukasovic Dec 01 '17 at 12:35
  • Based on what you added, I am wondering if you are mixing JPA and ES repositories. Does this answer help? https://stackoverflow.com/a/32879779/4614870 – Brian Dec 01 '17 at 12:42
  • @Brian I have no Jpa repos. Only this single Elastic search repo, and its implementation. I don't use spring boot. – Bojan Vukasovic Dec 01 '17 at 12:57

1 Answers1

0

I found a reason. It is method getBasePackages inside file RepositoryBeanDefinitionBuilder in spring-data-commons that makes you have implementation in same folder like this

public Iterable<String> getBasePackages() {
            return Collections.singleton(ClassUtils.getPackageName(fragmentInterfaceName));
        }

If i change this to

public Iterable<String> getBasePackages() {
            return configuration.getBasePackages();
        }

everything works as expected. Will check why the guys from spring did it this way...

Bojan Vukasovic
  • 2,054
  • 22
  • 43