java - Spring Boot错误org.springframework.beans.factory.UnsatisfiedDependencyException

标签 java spring-boot

org.springframework.beans.factory.UnsatisfiedDependencyException:创建文件[C:\ Users \ guptadee \ Projects \ Server \ Vista \ docstash_api_migration \ target \ classes \ com \ adp \ avs \ tax \ form中定义的名称为'producer'的bean时出错\\ DocStashElasticMigration \ Service \ Producer.class]:通过构造函数参数0表示的不满意依赖关系;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'java.util.concurrent.BlockingQueue'的合格Bean:期望至少有1个合格为自动装配候选的Bean。依赖项注释:{}
    在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1201)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:312)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)〜[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)〜[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)上[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
    在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)上[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
    在org.springframework.boot.SpringApplication.run(SpringApplication.java:303)上[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
    在org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
    在org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
    com.adp.avs.tax.form.DocStashElasticMigration.DocStashElasticMigrationApplication.main(DocStashElasticMigrationApplication.java:29)[classes /:na]
由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'java.util.concurrent.BlockingQueue'的合格Bean:期望至少有1个合格为自动装配候选的Bean。依赖项注释:{}
    在org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)〜[spring-beans-4.3.17.RELEASE.jar:4.3.17.RELEASE]
    ...省略了18个通用框架


  迁移.java


@Service
public class Migration {

    @Autowired
    private TransportClient transportClient;

    @Autowired
    ClientDao clientDao;

    @Value("#{'${quarterly.form}'.split(',')}")
    private List<String> quarterlyForm;

    @Value("#{'${yearly.form}'.split(',')}")
    private List<String> yearlyForm;

    @Value("${threadCount:5}")
    private int threadCount;


    private final String oldIndex = "taxdocument";

    private final String newTaxformIndex = "";

    private final String newDocumentIndex = "";

    public static String type = "document";


    public void migratetoNewIndex(int year, int qtr) throws Exception{
        //Creating BlockingQueue of size 2000
        BlockingQueue<OutputDocument> queue = new ArrayBlockingQueue<OutputDocument>(2000);
        final Map<String,List<OrganizationUnit>> organizationUnitMap = clientDao.getAllOrg(String.valueOf(year).substring(2), String.valueOf(qtr));
        Producer producer = new Producer(queue,year,qtr);
        Thread producerThread = new Thread(producer);
        producerThread.start();
        List<Thread> consumerList = new ArrayList<Thread>();
        for(int i=0;i<threadCount;i++) {
            Consumer consumer = new Consumer(queue, organizationUnitMap);
            Thread T1 = new Thread(consumer);
            T1.start();
            consumerList.add(T1);
        }
        for (int i = 0; i < consumerList.size(); i++) {
            consumerList.get(i).join();
        }
        System.out.println("Producer and Consumer has been started");

    }

}



  Producer.java


@Component
public class Producer implements Runnable {

    @Autowired
    private TransportClient transportClient;

    @Value("#{'${quarterly.form}'.split(',')}")
    private List<String> quarterlyForm;

    @Value("#{'${yearly.form}'.split(',')}")
    private List<String> yearlyForm;

    @Value("${threadCount:5}")
    private int threadCount;

    private final String oldIndex = "taxdocument";

    private final String type = "document";

    private int year;

    private int qtr;


    private BlockingQueue<OutputDocument> queue;

    public Producer(BlockingQueue<OutputDocument> q, int year,int qtr) {
        this.queue = q;
        this.year=year;
        this.qtr=qtr;

    }

    @Override
    public void run() {

        List subcatecory = new ArrayList();
        subcatecory.addAll(quarterlyForm);
        try {
            List<String> yearQtr = new ArrayList<String>();
            yearQtr.add(year + "/" + qtr);
            if (qtr == 4) {
                subcatecory.addAll(yearlyForm);
                yearQtr.add(String.valueOf(year));
            }
            SearchResponse scrollResp = transportClient.prepareSearch(oldIndex)
                    .setTypes(type)
                    .addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)
                    .setScroll(new TimeValue(600000))
                    .setSize(1000)
                    .setQuery(boolQuery().must(QueryBuilders.termsQuery("subCategoryCode.codeValue", subcatecory))
                            .must(QueryBuilders.termsQuery("applicationData.yearQuarter", yearQtr)))
                    .get(); //max of 100 hits will be returned for each scroll

            if (scrollResp.getHits().getTotalHits() > 0) {
                OutputDocument outputDocument = null;
                Map<String, Object> responseMap = new HashMap<String, Object>();
                ObjectMapper mapper = new ObjectMapper();
                List<OutputDocument> documentList = new ArrayList<OutputDocument>();
                do {
                    for (SearchHit hit : scrollResp.getHits().getHits()) {
                        responseMap = hit.sourceAsMap();
                        responseMap.remove("storeKey");
                        outputDocument = mapper.convertValue(responseMap, OutputDocument.class);
                        queue.put(outputDocument);
                    }
                    scrollResp = transportClient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
                } while (scrollResp.getHits().getHits().length != 0); // Zero hits mark the end of the scroll and the while loop.

                //exit message to child threads
                for(int i=0; i<threadCount; i++) {
                    OutputDocument exitMessage = new OutputDocument();
                    exitMessage.setItemID("exit");
                    queue.put(exitMessage);
                }
            }

        } catch (Exception e) {

        }

    }
}

最佳答案

参见public Producer(BlockingQueue q,int year,int qtr)
您未声明类型的工厂实例合格bean
'java.util.concurrent.BlockingQueue'BlockingQueue
您可以添加工厂方法或工厂bean

@Bean
public BlockingQueue<OutputDocument> createBlockingQueue() {

}

关于java - Spring Boot错误org.springframework.beans.factory.UnsatisfiedDependencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50335162/

相关文章:

eclipse - 找不到主类 : Program will exit

java - JAVA中的AES加密漏洞

java - 如何为生产者确保 kafka 主题?

java - 以oracle为数据库打包spring boot应用

java - Java 中的 ADT 理解 - 将元素添加到 Arraylist 的尾部

java - 当服务器 Web 服务关闭时,.Net Web 服务客户端需要很长时间才能调用失败

java - 如何将文件路径发送到 mysql 表

java - 使用 Spring Boot : Could not resolve placeholder 进行 Maven 资源过滤

spring-boot - Git 上的 Spring Boot 配置

java - 创建类路径资源中定义的名称为 'xxxEntityManagerFactory' 的 bean 时出错