无法为 class 的参数 [IProductManager] 注入值,不存在类型的 bean

Failed to inject value for parameter [IProductManager] of class, No bean of type exists

Micronaut 的依赖注入问题。我正在使用 Micronaut 版本 2.1.0,并且一直面临依赖注入问题。

{
  "message": "Internal Server Error: Failed to inject value for parameter [IProductManager] of class: fete.bird.api.v1.controller.ProductController\n\nMessage: No bean of type [fete.bird.manager.IProductManager] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).\nPath Taken: new ProductController([IProductManager IProductManager])"
}

界面

@Introspected
public interface IProductManager {
    List<ProductViewModel> findFreeText(String text);
}

实施

@Singleton
public class ProductManager implements IProductManager{
    private final ApplicationContext applicationContext;
    private static final Logger LOG = LoggerFactory.getLogger(ProductManager.class);
    public ProductManager(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Override
    public List<ProductViewModel> findFreeText(String text) {
        LOG.info("Manager --> Finding all the products");
        final List<ProductViewModel> model = new ArrayList<>();
        
         return model;
    }
}

控制器

@Controller("/api/v1/product")
public class ProductController {
    private static final Logger LOG = LoggerFactory.getLogger(ProductController.class);
    private final IProductManager iProductManager;

    public ProductController(IProductManager IProductManager) {
        this.iProductManager = IProductManager;
    }

    @Get(uri = "/{text}")
    List<ProductViewModel> freeTextSearch(String text) {
        LOG.info("Controller --> Finding all the products");
        return iProductManager.findFreeText(text);
    }
}

我正在使用 Intellj IDE。如果我删除 build 文件夹并且 运行 应用程序一切正常,但是多次 运行ning 应用程序会不断出现上述错误。每次我需要删除构建文件夹以使其工作时

我希望您遇到 https://github.com/micronaut-projects/micronaut-core/issues/4277 中描述的错误。

如果是这种情况,您可以按照该错误报告中所述禁用增量编译来解决问题。请注意,进行完全干净的构建也可能会解决此问题,但只能在下次构建触发相同问题时才能解决。