Symfony 3.4升级至6.0.1遇防火墙错误:服务类未找到
解决Symfony 3.4升级至6.0.1时
security.listener.user_checker.integration类找不到错误 问题根源
Symfony 6.x安全组件架构与3.4版本差异显著,用户检查器(UserChecker)的注册逻辑完全重构。你看到的ChildDefinition依赖父服务定义,但由于防火墙配置缺失关键项,框架无法正确解析父服务关联的类,导致空类名错误。
修复步骤
显式配置用户检查器:在每个防火墙块中添加
user_checker项,指定默认或自定义的用户检查器服务ID:integration: pattern: ^/integration host: %base_host% stateless: true custom_authenticators: - integration.authenticator.token provider: integration_provider user_checker: security.user_checker # 使用Symfony默认用户检查器若使用自定义用户检查器,替换为你的服务ID即可。
确认父服务定义:
security.listener.user_checker.integration的父服务是security.listener.user_checker,对应类为Symfony\Component\Security\Http\EventListener\UserCheckerListener。该类由SecurityBundle默认注册,可在组件的security_listeners.xml(或yaml)配置文件中找到其定义。清理缓存:升级后必须执行缓存清理命令,确保容器重新编译:
php bin/console cache:clear --env=prod php bin/console cache:clear --env=dev
关于RegisterListenersPass的工作逻辑
RegisterListenersPass负责收集安全监听器并注册到事件调度器。对于用户检查器监听器,它会基于父服务security.listener.user_checker创建子服务(即你看到的ChildDefinition)。父服务已指定UserCheckerListener类,子服务无需重复声明类,只需继承父服务配置并绑定当前防火墙的参数。
内容的提问来源于stack exchange,提问作者Oleg
相关产品推荐
相关产品推荐

