fos_oauth_server.client_manager.default未加载

Dan*_*eil 1 authentication symfony fosrestbundle fosoauthserverbundle

从上周开始我就在尝试让 FOS Auth Server Bundle 与 Symfony4 一起工作。如果我想使用我创建的创建客户端命令,则会出现此错误消息。

编译容器时,“fos_oauth_server.client_manager.default”服务或别名已被删除或内联。您应该将其公开,或者停止直接使用容器并改为依赖项注入。

有人有同样的问题吗?

小智 5

我也有同样的问题。尝试像这样注入服务:

    <?php
namespace App\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use FOS\OAuthServerBundle\Entity\ClientManager;

class CreateClientCommand extends ContainerAwareCommand
{
    protected static $defaultName = 'create:client';
    private $client_manager;

    public function __construct(ClientManager $client_manager)
    {
        parent::__construct();
        $this->client_manager = $client_manager;       
    }
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

Cannot autowire service "App\Command\CreateClientCommand": argument "$client_manager" of method "__construct()" ref  
  erences class "FOS\OAuthServerBundle\Entity\ClientManager" but no such service exists. It cannot be auto-registered  
   because it is from a different root namespace.
Run Code Online (Sandbox Code Playgroud)

所以我在 services.yaml 中注册了我的命令:

App\Command\CreateClientCommand:
         arguments:
            $client_manager: '@fos_oauth_server.client_manager.default' 
Run Code Online (Sandbox Code Playgroud)

现在可以了:)