【问题标题】:Symfony2 ParamConverter not associated with @Annotation (cache must be cleared after any file change)Symfony2 ParamConverter 不与@Annotation 关联(任何文件更改后必须清除缓存)
【发布时间】:2026-01-22 19:15:01
【问题描述】:

我有一个控制器,它对路由、方法、模板和 ParamConverter 使用注解。
如果我在下一页加载对文件进行任何更改(甚至是空格更改或注释),则会发生以下错误

Cannot import resource "/home/sites/MySite/src/Acme/Bundle/MyBundle/Controller/" from "/home/sites/MySite/app/config/routing.yml".

FileLoaderLoadException: Cannot import resource "/home/sites/MySite/src/Acme/Bundle/MyBundle/Controller/" from "/home/sites/MySite/app/config/routing.yml"

AnnotationException: [Semantical Error] The class "Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter". If it is indeed no annotation, then you need to add @IgnoreAnnotation("ParamConverter") to the _class_ doc comment of method Acme\Bundle\MyBundle\Controller\DefaultController::viewAction().

如果我清除了我的缓存,那么它会再次起作用,但只有在我进行另一次更改之前,它才会再次发生。 在读取配置的注释信息时似乎遇到了问题,但我不明白为什么它在实际上没有对任何注释进行更改时起作用/不起作用。

【问题讨论】:

  • 你能告诉我们你的控制器文件吗?
  • 你使用的是什么版本的 Symfony?您在使用 eAccelerator 吗?
  • 在将项目升级到 Symfony 2.2 后,我遇到了同样的问题。它似乎只发生在 prod 环境中,dev 没问题。它在清除缓存后工作,直到我在任何操作上使用 ParamConverter 击中另一个控制器,不一定是我正在击中的操作。之后,任何具有 ParamConverter 的控制器中的任何操作都不起作用。
  • 不使用eAccelerator,最新稳定版2.2.0。谢谢 tetranz,很高兴知道这不仅仅是我。

标签: php symfony annotations


【解决方案1】:

啊,这是一个已知的错误,已在 FrameworkExtraBundle 中修复。

https://github.com/symfony/symfony/issues/7283

现在要获取最新版本,只需将该库的要求更改为 dev-master

"require": {
    ...
    "symfony/symfony": "2.2.*",
    "sensio/framework-extra-bundle": "dev-master",
   ...
},

并运行作曲家更新

【讨论】:

  • 伙计,你成就了我的一天。谢谢
  • sensio/framework-extra-bundle v2.2.1 包含修复,不再需要使用 dev-master,您可以使用 2.2.* 并获取最新的标记版本。