简体   繁体   English

无法自动装配服务 ServiceEntityRepository 不存在此类服务。 API 平台下的 Symfony

[英]Cannot autowire service ServiceEntityRepository no such service exists. Symfony under API Platform

We are using API Platform to build our APP and we got stuck into a bug that looks environment related to us.我们正在使用 API 平台构建我们的应用程序,我们陷入了一个看起来与我们相关的环境的错误。 We are 4 developpers, 3 of us under windows have the same issue while the one under mac os can't reproduice it and everything's working fine for him.我们是 4 个开发人员,我们中的 3 个在 windows 下有同样的问题,而在 mac os 下的一个无法重现它并且一切正常。 We are working with the official docker and we all got it updated.我们正在与官方 docker 合作,我们都更新了它。

I've tried everything related I could find on google, checked the doc again and nothing has worked for us that's why I'm asking for your help.我已经尝试了我可以在谷歌上找到的所有相关内容,再次检查了文档,但对我们没有任何帮助,这就是我寻求你帮助的原因。

Now let me explain whats's happening.现在让我解释一下发生了什么。 We are on a branch, everthings is working fine, all our tests are working good with phpunit.我们在一个分支上,一切正常,我们所有的测试都与 phpunit 一起工作。 And at some point when we create a new entity, the entity and repository files are generated, and after that, any command we could try (migration, make new entity, clear cache, testing with phpunit) will lead to that error:在某些时候,当我们创建一个新实体时,会生成实体和存储库文件,之后,我们可以尝试的任何命令(迁移、创建新实体、清除缓存、使用 phpunit 进行测试)都会导致该错误:

Cannot autowire service "App\Command\CreateActionsCommand": argument "$roleRepository" of method "__construct()" references class "App\Repository\RoleRepository" but no such service exists.

I checked the RoleRepository, everything's is fine compared to the related documentation ( https://symfony.com/doc/current/doctrine.html ), also checked the services.yaml file, autowire should be able to access the repository file.我检查了 RoleRepository,与相关文档( https://symfony.com/doc/current/doctrine.html )相比,一切都很好,还检查了 services.yaml 文件,autowire 应该能够访问存储库文件。

Something very weird we found while trying to debug, if we manually remove any random repository file, we are able to make to use commands again.我们在尝试调试时发现了一些非常奇怪的事情,如果我们手动删除任何随机存储库文件,我们就可以再次使用命令。

Here's my RoleRepository file:这是我的 RoleRepository 文件:

<?php

namespace App\Repository;

use App\Entity\Role;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @method Role|null find($id, $lockMode = null, $lockVersion = null)
 * @method Role|null findOneBy(array $criteria, array $orderBy = null)
 * @method Role[]    findAll()
 * @method Role[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class RoleRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Role::class);
    }
}

Let me know if you need to know any details, thanks for your help !如果您需要了解任何详细信息,请告诉我,感谢您的帮助!

I cloned and installed the project in a debian VM and everything's working fine now.我在 debian VM 中克隆并安装了该项目,现在一切正常。 Windows and Docker issue it looks like. Windows 和 Docker 问题看起来像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony 无法自动装配服务 不存在此类服务 - Symfony cannot autowire service no such service exists 无法在 symfony 中自动装配服务 - Cannot autowire service in symfony Symfony 5.1 - 无法自动装配服务 - Symfony 5.1 - Cannot autowire service 无法在 Symfony 3.4 和 FosUserBundle 中自动装配服务 - Cannot autowire service in Symfony 3.4 and FosUserBundle 无法自动服务FOSUserBundle,Symfony 3.4 - Cannot autowire service FOSUserBundle, Symfony 3.4 Symfony:无法自动装配“Controller:method()”的参数 $injectedVar:它引用 class“App\Entity\Entity”,但不存在此类服务 - Symfony: Cannot autowire argument $injectedVar of "Controller:method()": it references class "App\Entity\Entity" but no such service exists 无法自动装配“App\Controller\HomeController”参数 $:它引用 class“Symfony\Component\Form\SubmitButton”但不存在此类服务 - Cannot autowire argument $of "App\Controller\HomeController": it references class "Symfony\Component\Form\SubmitButton" but no such service exists 无法自动装配服务:参数引用 class 但不存在此类服务 - Cannot autowire service: Argument references class but no such service exists Symfony 3.4 自动装配服务 - Symfony 3.4 autowire service Symfony 4.4:无法自动连接服务“Symfony\Component\Validator\Context\ExecutionContextFactory” - Symfony 4.4: Cannot autowire service "Symfony\Component\Validator\Context\ExecutionContextFactory"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM