Symfony 6.3自定义AccessToken Handler报错:父定义不存在
问题解决:自定义AccessToken Handler报错“Parent definition不存在”
错误原因
你的配置文件里指定的令牌处理器命名空间是Api\Security\AccessTokenHandler,但实际代码中的类命名空间是App\Security\AccessTokenHandler,两者不匹配,导致Symfony找不到对应的服务定义。
修复步骤
修正security.yaml中的命名空间
将token_handler的值改为实际的类命名空间:security: password_hashers: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' providers: users_in_memory: { memory: null } firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false api: pattern: ^/api stateless: true access_token: token_handler: App\Security\AccessTokenHandler确认服务自动注册(可选)
Symfony 6+默认会自动注册App\命名空间下的类作为服务,且如果你的类实现了AccessTokenHandlerInterface,autoconfigure会自动配置相关服务标签。如果项目修改过服务自动注册规则,需要确保在services.yaml中手动注册:services: App\Security\AccessTokenHandler: autoconfigure: true清除缓存
执行缓存清除命令确保配置生效:php bin/console cache:clear
内容的提问来源于stack exchange,提问作者Nuryagdy Mustapayev
相关产品推荐
相关产品推荐

