spring数据elasticsearch bean创建

时间:2017-04-10 09:31:18

标签: java spring elasticsearch spring-data

我遇到弹簧数据弹性搜索bean创建的问题。未创建弹性搜索存储库bean。我不明白可能是什么问题。这是mo代码:

配置类:

    package example.test.mongo.config;

    import com.mongodb.MongoClient;
    import org.elasticsearch.client.Client;
    import org.elasticsearch.client.transport.TransportClient;
    import org.elasticsearch.common.settings.Settings;
    import org.elasticsearch.common.transport.InetSocketTransportAddress;
    import org.elasticsearch.transport.client.PreBuiltTransportClient;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.EnableAspectJAutoProxy;
    import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
    import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
    import org.springframework.data.mongodb.core.MongoTemplate;
    import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

    import java.net.InetAddress;
    import java.net.UnknownHostException;


    @Configuration
    @EnableMongoRepositories({"example.test.mongo.app.repo.mongo"})
    @EnableElasticsearchRepositories({"example.test.mongo.app.repo.elasticsearch"})
    @EnableAspectJAutoProxy
    @ComponentScan(basePackages = {"example.test.mongo.app"})
    public class AppConfig {

    @Bean
    public MongoTemplate mongoTemplate() throws Exception {
        return new MongoTemplate(new MongoClient("127.0.0.1:27017"), "jobvacancy");
    }

    @Bean
    public Client client() throws UnknownHostException {
        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9200));
        return client;
    }

    @Bean
    public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
        return new ElasticsearchTemplate(client());
    }
}

mongodb和elastisearch存储库类位于不同的包中。 这是弹性搜索存储库类:

import eures.reg2018.poc.mongo.app.domain.blob.JobVacancyWithBlob;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;



public interface ElasticSearchTestRepository extends ElasticsearchRepository<Article, String> {
Page<Article> findByReference(String Reference, Pageable pageable);
}

例外是:

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticSearchTestRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
at     org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:240)
at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193)
at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095)
at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:923)
at     org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:804)
at     org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:558)
at     org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at     org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
at     org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220)
at     org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1260)
at     org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
at     org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at     org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at     org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
... 14 more

任何人都有任何想法为什么会发生此例外?

0 个答案:

没有答案