当前位置: 首页 > 知识库问答 >
问题:

组织。springframework。豆。工厂NoSuchBeanDefinitionException:没有类型为的限定bean

邢良才
2023-03-14

2020-09-23T15:28:00.3483912Zjava.lang.IllegalStateExcture:未能加载Application ationContext 2020-09-23T15:28:00.3489821Z引起的原因:org.springframework.beans.factory.不满意依赖异常:创建在文件[/home/run/work/comation-service中定义名为salecChannelEventProcator的bean时出错/calculation-service/target/classes/com/demo/calculation/saleschannel/SalecChannelEventProcessor.class]:通过构造函数参数1表示的不满足依赖关系;嵌套异常org.springframework.beans.factory.NoSuchBean定义异常:没有类型'de.demo.json.schema.JsonValidator'可用的限定bean:预计至少有1 bean有资格成为自动接线候选人。依赖注释:

import de.demo.json.schema.JsonValidator;
@Configuration
@ComponentScan( basePackages = {
        "com.demo",
        "de.demo" },
        excludeFilters = {
                @ComponentScan.Filter( Configuration.class )
        } )
@ImportResource("classpath:/spring-context.xml")
@Import({SwaggerConfig.class, SalesChannelSqsConfig.class})
public class SpringMvcConfig extends WebMvcConfigurationSupport {
 @Autowired private ApplicationContext applicationContext;

@Bean( name = "objectMapper" )
    public ObjectMapper getObjectMapper( JacksonService jacksonService ) {
        return jacksonService.getObjectMapper();
    }

@Bean(name = "jsonValidator")
    public JsonValidator jsonValidator() {
        return new JsonValidator();
    }
}

@Component
@Slf4j
@RequiredArgsConstructor
public class SalesChannelUpdateListerner {

  @NonNull
  private final SalesChannelService salesChannelService;

  @NonNull
  private final SalecChannelEventProcessor salecChannelEventProcessor;

  @SqsListener(value = "${sales.channel.update.queue.name}", deletionPolicy = ON_SUCCESS)
  @SneakyThrows
  public void receiveSalesChannelUpdateEvent(
      @NotificationMessage EnvelopedMessage envelopedMessage) {
    log.debug("Received message from sales channel update event queue : {}"
}


@Component
@Slf4j
@RequiredArgsConstructor
public class SalecChannelEventProcessor {

  private static final String MESSAGE_TYPE = "sales_channel_update";

  @NonNull
  private final ObjectMapper objectMapper;
  @NonNull 
  private final JsonValidator jsonValidator;



  @SneakyThrows(JsonProcessingException.class)
  public boolean isValid(EnvelopedMessage envelopedMessage) {
    if (!MESSAGE_TYPE.equals(envelopedMessage.getType())) {
      return false;
    }
    return jsonValidator.validate(envelopedMessage);
  }

共有1个答案

汲灿
2023-03-14

您需要创建JsonValidatorbean。您需要将您的SaleChannelEventProcessor更改为:

@Component
@Slf4j
@RequiredArgsConstructor
public class SalecChannelEventProcessor {

  private static final String MESSAGE_TYPE = "sales_channel_update";

  @NonNull
  private final ObjectMapper objectMapper;

  @Bean
  public JsonValidator  jsonValidator(){
       return new JsonValidator();
  }

  @SneakyThrows(JsonProcessingException.class)
  public boolean isValid(EnvelopedMessage envelopedMessage) {
      if (!MESSAGE_TYPE.equals(envelopedMessage.getType())) {
          return false;
      }
      return jsonValidator().validate(envelopedMessage);
  }
}
 类似资料: