未考虑 Symfony 属性路由

Symfony attributes routes not taken into account

我在 PHP 8 上有一个现有的 Symfony 5.2 应用程序 运行,它使用 YAML 配置路由。

我想将其转换为使用属性。我添加了一个 config/routes/annotations.yaml 文件:

controllers:
  resource: ../../src/UserInterface/Web/
  type: annotation

kernel:
  resource: ../../src/Kernel.php
  type: annotation

(是的,我的控制器在 src/UserInterface/Web 之下!)

我从 .yaml 配置文件中删除了路由,并向控制器添加了属性:

...
use Symfony\Component\Routing\Annotation\Route;

class HomeController
{
    #[Route('/', name: 'homepage')]
    public function index(Request $request): Response { ... }
}

但是我的主页现在显示“欢迎使用 Symfony”页面。我试过了:

bin/console debug:router

但它不显示 homepage 路线。我尝试改用 Doctrine 注释:

/**
 * @Route("/", name="homepage")
 */
public function index(Request $request): Response { ... }

也没有运气。我尝试清除缓存:

bin/console cache:clear

但问题依然存在。 我错过了什么?

注意:被证明是问题正确答案的评论是基于提供的信息和关于缓存被清除的讨论的假设。

在运行之后没有列出路由的事实:

bin/console debug:router

是在 ../../src/Kernel.php 中发现的 Kernel::configureRoutes() 方法以某种方式被篡改的线索。

default method implementation 缺少以下代码行:

$routes->import('../config/{routes}/*.yaml');

经问题作者确认。