在服务器上部署我的 Symfony 应用程序后,我使用以下命令删除缓存:
sudo rm -rf app/cache
通常一切正常,但有时我会收到一条异常消息:
Cannot import resource
"/var/projectsssssss/src/Project/UserPanelBundle/Controller" from
"/var/projectsssssss/src/Project/UserPanelBundle/Resources/config/routing.yml".
然后,我再次删除缓存,它一直在工作,直到下一次随机部署。我为路线使用注释。使用 ControllergenerateUrl
方法时抛出异常这里是堆栈跟踪:
#0 /var/project/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(75): Symfony\\Component\\Config\\Loader\\FileLoader->import('@UserPanelBundl...', 'annotation', false, '/var/projectsss...')
#1 /var/project/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php(75): Symfony\\Component\\Routing\\Loader\\YamlFileLoader->load('/var/projectsss...', NULL)
#2 /var/project/vendor/symfony/symfony/src/Symfony/Component/Routing/Loader/YamlFileLoader.php(75): Symfony\\Component\\Config\\Loader\\FileLoader->import('@UserPanelBundl...', NULL, false, '/var/projectsss...')
#3 /var/project/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/DelegatingLoader.php(52): Symfony\\Component\\Routing\\Loader\\YamlFileLoader->load('/var/projectsss...', NULL)
#4 /var/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Routing/DelegatingLoader.php(57): Symfony\\Component\\Config\\Loader\\DelegatingLoader->load('/var/projectsss...', NULL)
#5 /var/project/app/cache/main/classes.php(1742): Symfony\\Bundle\\FrameworkBundle\\Routing\\DelegatingLoader->load('/var/projectsss...', NULL)
#6 /var/project/app/cache/main/classes.php(1451): Symfony\\Bundle\\FrameworkBundle\\Routing\\Router->getRouteCollection()
#7 /var/project/app/cache/main/classes.php(1400): Symfony\\Component\\Routing\\Router->getGenerator()
#8 /var/project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php(45): Symfony\\Component\\Routing\\Router->generate('userpanel_apps', Array, false)
#9 /var/project/src/Project/UserPanelBundle/Controller/AppsController.php(26): Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller->generateUrl('userpanel_apps', Array)
#10 [internal function]: Project\\UserPanelBundle\\Controller\\AppsController->indexAction()
#11 /var/project/app/bootstrap.php.cache(1426): call_user_func_array(Array, Array)
#12 /var/project/app/bootstrap.php.cache(1390): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)
#13 /var/project/app/bootstrap.php.cache(1566): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)
#14 /var/project/app/bootstrap.php.cache(617): Symfony\\Bundle\\FrameworkBundle\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)
#15 /var/project/web/app.php(28): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))
#16 {main}
我想缓存生成存在一些问题,但如何避免呢?
编辑
我的routing.yml
:
default:
resource: "@UserPanelBundle/Controller"
type: annotation