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

huangapple go评论76阅读模式
英文:

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.

{
  &quot;message&quot;: &quot;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 &#39;io.micronaut.context.condition&#39; 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 &#39;micronaut-inject-java&#39; dependency should be configured as an annotation processor).\nPath Taken: new ProductController([IProductManager IProductManager])&quot;
}

Interface

@Introspected
public interface IProductManager {
    List&lt;ProductViewModel&gt; 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&lt;ProductViewModel&gt; findFreeText(String text) {
        LOG.info(&quot;Manager --&gt; Finding all the products&quot;);
        final List&lt;ProductViewModel&gt; model = new ArrayList&lt;&gt;();
        
         return model;
    }
}

Controller

@Controller(&quot;/api/v1/product&quot;)
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 = &quot;/{text}&quot;)
    List&lt;ProductViewModel&gt; freeTextSearch(String text) {
        LOG.info(&quot;Controller --&gt; Finding all the products&quot;);
        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.

huangapple
  • 本文由 发表于 2020年10月8日 23:18:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/64265642.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定