Symfony 4.3-无法自动装配引用类“ Symfony \ Component \ Security \ Core \ Security”的服务参数

时间:2019-09-14 23:50:09

标签: symfony security service

我正在使用Symfony 4.3。

我在控制器方法中自动装配服务参数有问题。 似乎找不到安全类。

我通过composer require symfony/security

安装了安全组件

这是“ composer show”中的行:

symfony/security v4.3.4 Symfony Security Component

Composer.json:

"symfony/security": "4.3.*",

Services.yaml:

parameters:

services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

HomeController.php:

use App\Service\DB\DBALProvider;

class HomeController extends AbstractController
{
    /**
     * @Route("/", name="index")
     */
    public function index(DBALProvider $DBALProvider)
    {

DBALProvider.php:

use Symfony\Component\Security\Core\Security;
use Doctrine\ORM\EntityManagerInterface;

class DBALProvider
{
    private $entityManager;
    private $context;
    private $user;

    public function __construct(EntityManagerInterface $entityManager, Security $security)
    {

输入“ /”路线时显示的错误

Cannot resolve argument $DBALProvider of "App\Controller\HomeController::index()": Cannot autowire service "App\Service\DB\DBALProvider": argument "$security" of method "__construct()" references class "Symfony\Component\Security\Core\Security" but no such service exists.

谢谢您的建议。

1 个答案:

答案 0 :(得分:0)

composer require symfony/security-bundle

是解决方案(感谢Cerad)。

https://symfony.com/doc/current/security.html

好吧,我composer require symfony/security安装了所有必需的捆绑软件。