Symfony2 - DoctrineMongoDBBundle - Doctrine\Common\Annotations\AnnotationException
我正在尝试使用 DoctrineMongoDBBundle,但是,我遇到了问题。
在我的 config.yml 中,我有:
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options:
connect: true
default_database: symfony2
document_managers:
default:
auto_mapping: true
我的 User.php 类:
<?php
namespace HALL\HelloWorldBundle\Document;
use FOS\UserBundle\Document\User as BaseUser;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class User extends BaseUser
{
/** @MongoDB\Id(strategy="auto") */
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
当我运行命令时:
php app/console doctrine:mongodb:generate:documents HALLHelloWorldBundle
我收到以下错误:
[Doctrine\Common\Annotations\AnnotationException]
[语义错误] 注释 类中的“@Doctrine\ODM\MongoDB\Mapping\Annotations\Document” HALL\HelloWorldBundle\Document\User 不存在,或无法存在 自动加载。
有什么想法吗?注释已明确引用。
I'm trying to use the DoctrineMongoDBBundle, however, i'm running into an issue.
In my config.yml, I have:
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options:
connect: true
default_database: symfony2
document_managers:
default:
auto_mapping: true
My User.php class:
<?php
namespace HALL\HelloWorldBundle\Document;
use FOS\UserBundle\Document\User as BaseUser;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class User extends BaseUser
{
/** @MongoDB\Id(strategy="auto") */
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
When I run the command:
php app/console doctrine:mongodb:generate:documents HALLHelloWorldBundle
I get the following error:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation
"@Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class
HALL\HelloWorldBundle\Document\User does not exist, or could not be
auto-loaded.
Any ideas why? The annotation is clearly referenced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
找到解决方案。
<一href="http://groups.google.com/group/symfony2/browse_thread/thread/0d45a6bfe4b04ee7/645f347c77bdc3e6?show_docid=645f347c77bdc3e6 ">http://groups.google.com/group/symfony2/browse_thread/thread/0d45a6bfe4b04ee7/645f347c77bdc3e6?show_docid=645f347c77bdc3e6
在 app/autoload.php 中,我需要添加:
啊,我希望文档能告诉我这一点......
Solution found.
http://groups.google.com/group/symfony2/browse_thread/thread/0d45a6bfe4b04ee7/645f347c77bdc3e6?show_docid=645f347c77bdc3e6
in app/autoload.php, I needed to add:
Ah, I wish the documentation would tell me this....
像 Jamie 的解决方案中那样注册注释对我来说不起作用。它解决了这个问题,但意味着注释对象无法从缓存中反序列化。像这样注册注解:
意味着原来的问题已经解决,没有引入与缓存相关的问题。
Registering the annotations as in Jamie's solution did not work for me. It solved this problem but meant that the annotations object could not be unserialized from the cache . Registering the annotations like this:
Meant that the original issue was resolved without introducing the issue relating to the cache.
您应该在引导程序上注册注释类,这可以通过两种方式完成。使用 Richard 详细介绍的静态调用。或者...
您可以在驱动程序对象上使用 registerAnnotationClasses() 方法。这应该做完全相同的事情,但不需要路径参数(因为在引导程序上设置驱动程序时应该已经给出了路径参数)。
You should register the annotation classes on bootstrap, this can be done in 2 ways. Using the static call as detailed by Richard. Or...
You can use the registerAnnotationClasses() method on your driver object. This should do exactly the same thing but doesn't require a path parameter (as it should have already been given when setting up your driver on bootstrap).
在 DoctrineMongoDBBundle 文档中找到的解决方案< /a>
你的 app/autoload.php 必须是这样的:
Solution found in Documentation of DoctrineMongoDBBundle
your app/autoload.php must be like this :
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
在文档中你可以找到这部分配置
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
In the doc you can find this part of configuration