如何解决无法为类的参数[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.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。如果删除构建文件夹并运行应用程序,则一切正常,但是运行该应用程序时,多次仍会出现上述错误。每次我需要删除构建文件夹以使其正常工作
解决方法
我希望您遇到https://github.com/micronaut-projects/micronaut-core/issues/4277中描述的错误。
在这种情况下,您可以按照该错误报告中的说明,通过禁用增量编译来解决问题。请注意,执行完全干净的构建也可以解决该问题,但只能等到下一次该构建触发相同的问题时。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。