Symfony 当路由不';不存在

Symfony 当路由不';不存在,symfony,Symfony,我想显示404NotFound错误,当有人试图访问web中不存在的路由时 我在生产环境中不断遇到这种异常: Fatal error: Uncaught exception 'Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException' with message 'The token storage contains no authentication token. One possibl

我想显示404NotFound错误,当有人试图访问web中不存在的路由时

我在生产环境中不断遇到这种异常:

Fatal error: Uncaught exception 'Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException' with message 'The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.' in /<path>/app/cache/prod/classes.php:4626 Stack trace: #0 /<path>/app/cache/prod/classes.php(4364): Symfony\Component\Security\Core\Authorization\AuthorizationChecker->isGranted('ROLE_USER', NULL) #1 /<path>/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Extension/SecurityExtension.php(41): Symfony\Component\Security\Core\SecurityContext->isGranted('ROLE_USER', NULL) #2 /<path>/app/cache/prod/twig/9e/5d/2e6e87b557efe952c1ff84648c04bdb5d6870549f95d79526f65c94696d2.php(149): Symfony\Bridge\Twig\Extension\SecurityExtension->isGranted('ROLE_USER') #3 /<path>/app/cache/prod/classes.php(6519): __TwigTemplate_9e5d2e6e87b557efe952c1ff84648c04bdb5d6870549f95d79526f65c94696d2->d in /<path>/app/cache/prod/classes.php on line 6530

对我来说,这是因为提供者:

providers:
    fos_userbundle:
        id: fos_user.user_provider.username_email

当找不到路由时,将不创建令牌,并引发404异常,因此您的本应测试令牌的提供程序将失败并引发错误。

我深入研究,发现错误实际上是由twig引发的

我在404错误页面扩展的布局中使用了is_-grated('ROLE_-USER')。在检查权限之前,我必须检查用户是否已定义且不为空

这与2.1升级更改有关:

providers:
    fos_userbundle:
        id: fos_user.user_provider.username_email