UserPasswordEncoderInterface 自动装配不工作 Symfony 4.4
UserPasswordEncoderInterface Autowiring Not Working Symfony 4.4
我有一个超级基本的 API 端点,全新安装了 symfony 4.4,我收到以下错误:
Cannot autowire argument $passwordEncoder of
"App\Controller\AuthenticationController::authenticateAction()": it
references interface
"Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface"
but no such service exists.
我的控制器:
<?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 和 php7.2.20
几乎可以肯定这是某种配置问题,但我没有注意到我做错了什么。
伙计,我很聪明,这是一个配置问题!
我的 security.yaml
文件位于主 /config
目录中,而不是 /config/packages
目录中。好吧,也许我没那么聪明...
不确定它是如何到达那里的。我认为某些 out-dated 包无法在 config/packages
目录中找到它。
我生命中有 48 个小时...
我有一个超级基本的 API 端点,全新安装了 symfony 4.4,我收到以下错误:
Cannot autowire argument $passwordEncoder of "App\Controller\AuthenticationController::authenticateAction()": it references interface "Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface" but no such service exists.
我的控制器:
<?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 和 php7.2.20
几乎可以肯定这是某种配置问题,但我没有注意到我做错了什么。
伙计,我很聪明,这是一个配置问题!
我的 security.yaml
文件位于主 /config
目录中,而不是 /config/packages
目录中。好吧,也许我没那么聪明...
不确定它是如何到达那里的。我认为某些 out-dated 包无法在 config/packages
目录中找到它。
我生命中有 48 个小时...