I've defined a bundle Controller and Routing, but I get "Error: the controller does neither exist as service nor as class"

I've defined a bundle Controller and Routing, but I get "Error: the controller does neither exist as service nor as class"

我在 Symfony 4 的模块目录下创建了一个控制器 class。我的包的路由文件引用了它。我的 root 的路由文件包括包的路由文件。

但是我收到错误 500,“错误:控制器既不作为服务也不作为 class”存在。

为什么?

root/src/MyBundle/Resources/config/routing.YML

route_name:
  path: /test3
  controller: MyBundle\Controller\ExportCsvController::exportProductInCsv
  options:
    expose: true

root/config/routes/my_custom_routes.YML

route_name:
      resource: "@MyBundle/Resources/config/routing.yml"
      prefix:   /

root/src/MyBundle/Controller/ExportCsvController.PHP

<?php
namespace MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ExportCsvController extends Controller
{
    public function exportProductInCsv(): Response
    {
        return new Response(
            '<html><body>test</body></html>'
        );
    }
}

这是缓存(Symfony 缓存)的问题。使用此命令解决:php bin/console cache:clear --env=prod。现在文件 root/src/MyBundle/Resources/config/routing.YML 的内容被正确考虑了:).