问题描述
我有一个超级基本的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
几乎可以肯定这是某种配置问题,但是我没有遵循我做错的事情。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)