[英]Symfony2 - unable to autoload JMS serializer annotations
We are having issues autoloading JMSSerializer annotations in a symfony app. 在symfony应用程序中自动加载JMSSerializer批注时遇到问题。 We are getting:
[Semantical Error] The annotation "@JMS\\Serializer\\Annotation\\XMLRoot" in class Class\\Namespace\\ClassName does not exist, or could not be auto-loaded.
我们正在得到:
[Semantical Error] The annotation "@JMS\\Serializer\\Annotation\\XMLRoot" in class Class\\Namespace\\ClassName does not exist, or could not be auto-loaded.
We are using the standard symfony/composer autoloader, have "jms/serializer-bundle": "~1.0"
required in composer.json, and include the bundle in the AppKernel. 我们正在使用标准的symfony / composer自动加载器,在composer.json中具有
"jms/serializer-bundle": "~1.0"
〜1.0 "jms/serializer-bundle": "~1.0"
,并将该捆绑包包含在AppKernel中。 Other annotations (eg symfony route annotations) work correctly. 其他注释(例如symfony路由注释)可以正常工作。
We tried forcing to load the jms serializer annotations by modifying app_dev.php to: 我们尝试通过将app_dev.php修改为以下方式来强制加载jms序列化程序注释:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
AnnotationRegistry::registerFile("/srv/httpd/project/vendor/jms/serializer/src/JMS/Serializer/Annotation/XmlRoot.php");
AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer', "/srv/httpd/project/vendor/jms/serializer/src/");
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
We tried several variations of the AnnotationRegistery::...
calls. 我们尝试了
AnnotationRegistery::...
调用的几种变体。 AnnotationRegistry::registerFile("/srv/httpd/project/vendor/jms/serializer/src/JMS/Serializer/Annotation/XmlRoot.php");
seems to register correctly the XmlRoot annotations but other JMS annotations still fail. 似乎正确注册了XmlRoot注释,但其他JMS注释仍然失败。
Thanks. 谢谢。
you have to edit the vendor/autoload.php file,like below: 您必须编辑vendor / autoload.php文件,如下所示:
// autoload.php @generated by Composer
use Doctrine\Common\Annotations\AnnotationRegistry;
require_once __DIR__ . '/composer/autoload_real.php';
$loader = ComposerAutoloaderInitb6ddad78dfb081b4ad47d02feb034c25::getLoader();
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
return $loader;
Try to import namespace to Your Entity
with an alias: 尝试使用别名将名称空间导入到您的
Entity
:
<?php
use JMS\Serializer\Annotation as JMS
class SomeClass
{
/**
* @JMS/XMLRoot
*/
public $someProperty
}
Got same problem with Doctrine
elsewhere. 在其他地方也遇到了
Doctrine
问题。
Another possible reason for the same error:- 同一错误的另一个可能原因:
[Semantical Error] The annotation "@JMS\Serializer\Annotation\XMLRoot" in
class Class\Namespace\ClassName does not exist, or could not be auto-loaded.
is a missing call to AnnotationRegistry::registerLoader
. 是对
AnnotationRegistry::registerLoader
的缺少调用。
See documentation here - http://jmsyst.com/libs/serializer/master/configuration 在此处查看文档-http: //jmsyst.com/libs/serializer/master/configuration
If you are using the standalone library and you want to use annotations, the annotation registry must be initialized:
如果您正在使用独立库,并且想要使用注释,则必须初始化注释注册表:
Doctrine\\Common\\Annotations\\AnnotationRegistry::registerLoader('class_exists');
学说\\ COMMON \\注解\\ AnnotationRegistry :: registerLoader( 'class_exists');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.