升级到 Symfony 5.3 时,服务“...”依赖于不存在的服务“property_accessor”

问题描述

我们有一个关于 bundle https://github.com/liip/LiipTestFixturesBundle/tree/2.x 的问题(请注意,我是这个 bundle 的维护者之一,问题不在于在项目中使用那个 bundle)

Tests were broken 在主 2.x 分支上出现以下错误

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:服务“nelmio_alice.property_accessor.std”依赖于不存在的服务“property_accessor”。您的意思是:“nelmio_alice.property_accessor.std”?

以下是该服务在 vendor/nelmio/alice/src/Bridge/Symfony/Resources/config/property_access.xml 中的声明方式:

        <service id="nelmio_alice.property_accessor.std"
                 class="Nelmio\Alice\PropertyAccess\StdPropertyAccessor">
           <argument type="service" id="property_accessor" />
        </service>

应该调用代码,因为 NelmioAliceBundle 已加载到 AppKernel 中。

因此我们将 added 改为 composer.json禁止 symfony/property-access 5.3 并修复了错误

"symfony/property-access": "^4.4 || ^5.0,<5.3",

但是如果我们删除解决方法,它会再次中断。我不明白是什么导致了这个问题。

禁止 symfony/framework-bundle 5.3 也解决了这个问题:https://github.com/liip/LiipTestFixturesBundle/pull/127/commits/a534419e61ef90ca2685d697b89b2ce225712cdc


是什么导致我们使用 property_accessor 5.3 或 symfony/framework-bundle 5.3 时没有 symfony/property-access


如何复制错误

git clone git@github.com:liip/LiipTestFixturesBundle.git
cd LiipTestFixturesBundle
git checkout remove-required-symfony/property-access
composer install
vendor/bin/PHPunit --testdox tests/Test/ConfigEventsTest.PHP

解决方法

property_access: ~ 添加到 framework 配置修复了问题 (commit)。

该服务似乎在未配置时丢失。


该问题可在全新的 Symfony 安装中重现:

$ bin/console debug:container property_accessor
[critical] Error thrown while running command "debug:container property_accessor". Message: "No services found that match "property_accessor"."

                                                     
  No services found that match "property_accessor".  

如果您也有这个问题,请运行 composer require symfony/property-access

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...