gpt4 book ai didi

Spring找到2个候选人,但只有一个

转载 作者:行者123 更新时间:2023-12-02 04:33:46 25 4
gpt4 key购买 nike

我正在尝试升级 JHipster 项目,但是我发现了以下问题:

Description:
Parameter 0 of constructor in com.cervaki.config.AsyncConfiguration required a single bean, but 2 were found:
- jhipster-io.github.jhipster.config.JHipsterProperties: defined in null
- io.github.jhipster.config.JHipsterProperties: defined in null
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

我的理解是spring无法注入(inject)正确的bean,因为有两个候选者,但我只有 io.github.jhipster.config.JHipsterProperties 实现:
package com.cervaki.config;

import io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor;
import io.github.jhipster.config.JHipsterProperties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.*;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
@EnableScheduling
public class AsyncConfiguration implements AsyncConfigurer {

private final Logger log = LoggerFactory.getLogger(AsyncConfiguration.class);

private final JHipsterProperties jHipsterProperties;

public AsyncConfiguration(JHipsterProperties jHipsterProperties) {
this.jHipsterProperties = jHipsterProperties;
}

@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
log.debug("Creating Async Task Executor");
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
executor.setThreadNamePrefix("cervaki-Executor-");
return new ExceptionHandlingAsyncTaskExecutor(executor);
}

@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}
}

您可以下载 pom.xml here .

我在整个代码和库中进行了搜索以找到 jhipster-io.github.jhipster.config.JHipsterProperties 文件,但是我没有找到任何东西。
我能做些什么来解决这个问题?

最佳答案

在生成新的 JhipsterApp 后,我也遇到了这个问题,
和你一样 - 我在项目中找不到“jhipster-io”依赖项
我如何解决这个问题:

  • src/main/java/your/package/config创建一个“AppConfiguration.java”
  • 内容:
    import io.github.jhipster.config.JHipsterProperties;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Primary;

    @Configuration
    public class AppConfiguration {

    @Bean
    @Primary
    public JHipsterProperties jHipsterProperties() {
    return new JHipsterProperties();
    }
    }

  • 即使没有 @Primary - 我没有这个错误

    关于Spring找到2个候选人,但只有一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45946053/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com