简体   繁体   中英

Doctrine annotation error in production server

I have an error in production server which doesn't occur in my localhost :

AnnotationException: [Semantical Error] 
The annotation "@Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in method My\Bundle\Controller\MyController::indexAction() does not exist, or could not be auto-loaded.

This error happened in local when I tryed to update some packages with composer and this didn't solve it, I had to reinstall symfony and upload everything again, and is still happening .

Cache has been cleared so I guess it's not a cache thing.

AppKernel.php

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
public function registerBundles()
{
    $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new Symfony\Bundle\SecurityBundle\SecurityBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
        new Symfony\Bundle\MonologBundle\MonologBundle(),
        new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
        new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new JMS\AopBundle\JMSAopBundle(),
        new JMS\DiExtraBundle\JMSDiExtraBundle($this),
        new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
        new MyProject\PanelBundle\MyProjectPanelBundle(),
        new MyProject\ProductBundle\MyProjectProductBundle(),
        new Front\SiteBundle\FrontSiteBundle(),
   );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
        $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    }

    return $bundles;
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
    $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
}

Controller sample

And a sample of the anotattions in the controller which throws error:

/**
 * Lists all MyEnt entities.
 *
 * @Route("/", name="my_ent")
 * @Method("GET")
 * @Template("MyProjectPanelBundle:MyEnt:index.html.twig")
 */
public function indexAction($ident)
{

App/config/routing.yml

front_site:
    resource: "@FrontSiteBundle/Resources/config/routing.yml"
    prefix:   /

MyProject_product:
    resource: "@MyProjectProductBundle/Resources/config/routing.yml"
    prefix:   /

MyProject_panel:
    resource: "@MyProjectPanelBundle/Resources/config/routing.yml"
    prefix:   /

I had similar problem.

Importing Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route class with require_once solved it.

require_once __DIR__ . '/../vendor/sensio/framework-extra-bundle/Sensio/Bundle/FrameworkExtraBundle/Configuration/Route.php';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM