簡體   English   中英

嘗試清除 Symfony 4 應用程序緩存時出現“無法自動裝配服務”異常

[英]"Cannot autowire service" exception when trying to clear Symfony 4 application cache

我在 Symfony 4 下有一個項目,當我嘗試對我的項目進行 Composer 更新時出現此錯誤

     Executing script cache:clear 
Script cache:clear returned with error code 1[KO]
!!
!!  In DefinitionErrorExceptionPass.php line 54:
!!  

!!    Cannot autowire service "App\Repository\ActeRepository": argument "$registry" of method "__construct()" references interface "Symfony\Br  
!!    idge\Doctrine\RegistryInterface" but no such service exists. Try changing the type-hint to "Doctrine\Persistence\ManagerRegistry" instea  
!!    d.

!!  

!!
!!
Script @auto-scripts was called via post-install-cmd
 [KO]
<?php

和 ActeRepository 是以下

namespace App\Repository;

use App\Entity\Acte;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

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

    // /**
    //  * @return Acte[] Returns an array of Acte objects
    //  */
    /*
    public function findByExampleField($value)
    {
        return $this->createQueryBuilder('a')
            ->andWhere('a.exampleField = :val')
            ->setParameter('val', $value)
            ->orderBy('a.id', 'ASC')
            ->setMaxResults(10)
            ->getQuery()
            ->getResult()
        ;
    }
    */

    /*
    public function findOneBySomeField($value): ?Acte
    {
        return $this->createQueryBuilder('a')
            ->andWhere('a.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
    */
}

我現在不知道問題出在哪里並且項目無法更新我也嘗試刪除 var 和供應商文件並清除 composer 和 Symfony 的緩存但出現同樣的問題我現在不知道為什么我找到了多個建議的解決方案但是他們不工作?

構造函數應如下所示:

public function __construct(ManagerRegistry $registry)
{
    parent::__construct($registry, Acte::class);
}

添加使用語句:

use Doctrine\Common\Persistence\ManagerRegistry;

擴展類:

extends ServiceEntityRepository

要解決此問題,只需刪除您在ActeRepository.php中的構造ActeRepository.php ,它不是必需的。

這是一個自動裝配問題,因此如果您想將其保留在此處,則必須在存儲庫中初始化該字段。

如果它不起作用,請嘗試更改構造函數中的參數類型:

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;

class ActeRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Acte::class);
    }
    ...
}

我只是在所有存儲庫文件中替換 public function __construct(ManagerRegistry $registry) => public function __construct(\\Doctrine\\Common\\Persistence\\ManagerRegistry $registry) 認為

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM