UserPasswordEncoderInterface自动装配不起作用Symfony 4.4

问题描述

我有一个超级基本的API端点,它重新安装了symfony 4.4,出现以下错误

无法自动装配以下参数的参数$ passwordEncoder “ App \ Controller \ AuthenticationController :: authenticateAction()”:它 参考界面 “ Symfony \ Component \ Security \ Core \ Encoder \ UserPasswordEncoderInterface” 但不存在此类服务。

我的控制器:

<?PHP

namespace App\Controller;

use App\Entity\User;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\Route;
use Lexik\Bundle\JWTAuthenticationBundle\Encoder\JWTEncoderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;

/**
 * Class AuthenticationController
 *
 * @package App\Controller
 * @Route("/api/authentication")
 */
class AuthenticationController extends AbstractFOSRestController {

    /**
     * @Rest\Get("/authenticate")
     *
     * @param Request                      $request
     * @param UserPasswordEncoderInterface $passwordEncoder
     * @param JWTEncoderInterface          $JWTEncoder
     *
     * @return Response
     */
    public function authenticateAction (Request $request,UserPasswordEncoderInterface $passwordEncoder,JWTEncoderInterface $JWTEncoder) {
        exit;
    }
}

如果我删除UserPasswordEncoderInterface $passwordEncoder,我将一事无成(目前期望)。我的User实体没什么特别的,可以正确扩展UserInterface

services.yaml

# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands,event subscribers,etc.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/'
        exclude:
            - '../src/DependencyInjection/'
            - '../src/Entity/'
            - '../src/Kernel.PHP'
            - '../src/Tests/'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller/'
        tags: ['controller.service_arguments']

    # add more service deFinitions when explicit configuration is needed
    # please note that last deFinitions always *replace* prevIoUs ones

使用Symfony 4.4和PHP 7.2.20

几乎可以肯定这是某种配置问题,但是我没有遵循我做错的事情。

解决方法

我很聪明,这是配置问题!

我的security.yaml文件位于主/config目录中,而不位于/config/packages目录中。好吧,也许我不那么聪明...

不确定如何到达那里。我认为有些过时的软件包在config/packages目录中找不到它。

我一生要经历48个小时...