未能为类的参数[IProductManager]注入值,不存在类型为的bean


Micronaut的依赖注入问题。我使用的是Micronaut 2.1.0版本,并且一直面临依赖注入问题。
{
"message": "Internal Server Error: Failed to inject value for parameter [IProductManager] of class: fete.bird.api.v1.controller.ProductControllernnMessage: 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。如果我删除构建文件夹并运行应用程序,一切都很好,但在多次运行应用程序时,错误不断出现。每次我需要删除构建文件夹使其工作

我想您正在经历中描述的错误https://github.com/micronaut-projects/micronaut-core/issues/4277.

如果是这种情况,您可以通过禁用bug报告中描述的增量编译来消除问题。请注意,进行完全干净的构建也可以解决问题,但只能等到下次构建触发相同的问题。

相关内容

最新更新