英文:
Failed to inject value for parameter [IProductManager] of class, No bean of type exists
问题
Dependency Injection问题与Micronaut。我正在使用Micronaut版本2.1.0,并且一直面临着依赖注入问题。
接口
@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 --> 正在查找所有产品");
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 --> 正在查找所有产品");
return iProductManager.findFreeText(text);
}
}
我正在使用IntelliJ IDE。如果我删除构建文件夹并运行应用程序,一切都正常,但在多次运行应用程序时会不断出现上述错误。每次都需要删除构建文件夹才能使其正常工作。
英文:
Dependency Injection issue with Micronaut. I am using Micronaut version 2.1.0 and keep facing the dependency injection issue.
{
"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])"
}
Interface
@Introspected
public interface IProductManager {
List<ProductViewModel> findFreeText(String text);
}
Implementation
@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
@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);
}
}
I am using Intellj IDE. If I delete the build folder and run the application all works fine, but while running the application multiple time keeps getting above error. Every time I need to delete the build folder to make it work
答案1
得分: 1
我预计您正在遇到https://github.com/micronaut-projects/micronaut-core/issues/4277 上所描述的错误。
如果是这种情况,您可以按照该错误报告中的说明禁用增量编译,从而消除问题。请注意,进行完整的清理构建也可能会解决此问题,但只会在下次构建触发相同问题之前有效。
英文:
I expect you are experiencing the bug described at https://github.com/micronaut-projects/micronaut-core/issues/4277.
If that is the case, you can make the problem go away by disabling incremental compilation as described in that bug report. Note that doing a full clean build also may remedy the issue, but only until the next time the build triggers the same problem.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论