首页 > 解决方案 > 配方升级后symfony路由错误

问题描述

将 symfony/framework-bundle 配方从 4.4 升级到 5.1 版本后,我遇到了这个错误:

Argument 2 passed to Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator::__construct() must be an instance of Symfony\Component\Routing\Loader\PhpFileLoader, instance of Symfony\Component\Routing\Loader\AnnotationFileLoader given, called in /app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php on line 176

食谱做了这个改变: 在此处输入图像描述 在此处输入图像描述

另外,我发现如果我从vendor/symfony/routing/Loader/Configurator/RoutingConfigurator.php. 一切开始工作

也许我忘记了什么?或者如何在不更改供应商文件的情况下使其工作?

symfony 软件包:

composer show --installed|grep symfony
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
symfony/asset                        v5.1.3  Symfony Asset Component
symfony/browser-kit                  v5.1.3  Symfony BrowserKit Component
symfony/cache                        v5.1.3  Symfony Cache component with PSR-6, PSR...
symfony/cache-contracts              v2.1.3  Generic abstractions related to caching
symfony/config                       v5.1.3  Symfony Config Component
symfony/console                      v5.1.3  Symfony Console Component
symfony/css-selector                 v5.1.3  Symfony CssSelector Component
symfony/debug-bundle                 v5.1.3  Symfony DebugBundle
symfony/debug-pack                   v1.0.8  A debug pack for Symfony projects
symfony/dependency-injection         v5.1.3  Symfony DependencyInjection Component
symfony/deprecation-contracts        v2.1.3  A generic function and convention to tr...
symfony/doctrine-bridge              v5.1.3  Symfony Doctrine Bridge
symfony/dom-crawler                  v5.1.3  Symfony DomCrawler Component
symfony/dotenv                       v5.1.3  Registers environment variables from a ...
symfony/error-handler                v5.1.3  Symfony ErrorHandler Component
symfony/event-dispatcher             v5.1.3  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts   v2.1.3  Generic abstractions related to dispatc...
symfony/expression-language          v5.1.3  Symfony ExpressionLanguage Component
symfony/filesystem                   v5.1.3  Symfony Filesystem Component
symfony/finder                       v5.1.3  Symfony Finder Component
symfony/flex                         v1.9.1  Composer plugin for Symfony
symfony/form                         v5.1.3  Symfony Form Component
symfony/framework-bundle             v5.1.3  Symfony FrameworkBundle
symfony/http-client                  v5.1.3  Symfony HttpClient component
symfony/http-client-contracts        v2.1.3  Generic abstractions related to HTTP cl...
symfony/http-foundation              v5.1.3  Symfony HttpFoundation Component
symfony/http-kernel                  v5.1.3  Symfony HttpKernel Component
symfony/intl                         v5.1.3  A PHP replacement layer for the C intl ...
symfony/lock                         v5.1.3  Symfony Lock Component
symfony/mailer                       v5.1.3  Symfony Mailer Component
symfony/maker-bundle                 v1.20.0 Symfony Maker helps you create empty co...
symfony/mime                         v5.1.3  A library to manipulate MIME messages
symfony/monolog-bridge               v5.1.3  Symfony Monolog Bridge
symfony/monolog-bundle               v3.5.0  Symfony MonologBundle
symfony/options-resolver             v5.1.3  Symfony OptionsResolver Component
symfony/phpunit-bridge               v5.1.3  Symfony PHPUnit Bridge
symfony/polyfill-intl-grapheme       v1.18.1 Symfony polyfill for intl's grapheme_* ...
symfony/polyfill-intl-normalizer     v1.18.1 Symfony polyfill for intl's Normalizer ...
symfony/polyfill-php80               v1.18.1 Symfony polyfill backporting some PHP 8...
symfony/process                      v5.1.3  Symfony Process Component
symfony/profiler-pack                v1.0.5  A pack for the Symfony web profiler
symfony/property-access              v5.1.3  Symfony PropertyAccess Component
symfony/property-info                v5.1.3  Symfony Property Info Component
symfony/proxy-manager-bridge         v5.1.3  Symfony ProxyManager Bridge
symfony/routing                      v5.1.3  Symfony Routing Component
symfony/security-bundle              v5.1.3  Symfony SecurityBundle
symfony/security-core                v5.1.3  Symfony Security Component - Core Library
symfony/security-csrf                v5.1.3  Symfony Security Component - CSRF Library
symfony/security-guard               v5.1.3  Symfony Security Component - Guard
symfony/security-http                v5.1.3  Symfony Security Component - HTTP Integ...
symfony/service-contracts            v2.1.3  Generic abstractions related to writing...
symfony/stopwatch                    v5.1.3  Symfony Stopwatch Component
symfony/string                       v5.1.3  Symfony String component
symfony/swiftmailer-bundle           v3.4.0  Symfony SwiftmailerBundle
symfony/templating                   v5.1.3  Symfony Templating Component
symfony/test-pack                    v1.0.6  A pack for functional and end-to-end te...
symfony/translation                  v5.1.3  Symfony Translation Component
symfony/translation-contracts        v2.1.3  Generic abstractions related to transla...
symfony/twig-bridge                  v5.1.3  Symfony Twig Bridge
symfony/twig-bundle                  v5.1.3  Symfony TwigBundle
symfony/validator                    v5.1.3  Symfony Validator Component
symfony/var-dumper                   v5.1.3  Symfony mechanism for exploring and dum...
symfony/var-exporter                 v5.1.3  A blend of var_export() + serialize() t...
symfony/web-profiler-bundle          v5.1.3  Symfony WebProfilerBundle
symfony/webpack-encore-bundle        v1.7.3  Integration with your Symfony app & Web...
symfony/yaml                         v5.1.3  Symfony Yaml Component

标签: phpsymfonysymfony5

解决方案


对于解决方法,您应该将其添加到您的配置中:

sensio_framework_extra:
    router:
        annotations: false

修复已合并https://github.com/symfony/symfony/pull/38226


推荐阅读