简体   繁体   中英

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. 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. We are working with the official docker and we all got it updated.

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. 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:

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.

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:

<?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. Windows and Docker issue it looks like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM