doufeng1249
doufeng1249
2017-07-25 15:39

Symfony从2.8-3.3切换到ClassNotFoundException使用语句缺少命名空间?

已采纳

Just recently we decided to upgrade from symfony 2.8 too 3.3 with this being noted I felt it was best to start a fresh symfony project and just pull over some parts of the project and change the key needed items that changed over this major version upgrade. I have worked out most of the issues however currently I get this meaning that I may have more issues that I suspect. here is the current one:

C:\xampp\htdocs\Fresh_Api>php bin/console server:run PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to lo ad class "CommandListener" from namespace "Directive\MultiTenant\MasterBundle\EventListener". Did you forget a "use" statement for another namespace? in C:\xampp\htdocs\Fresh_Api\var\cache\dev\a ppDevDebugProjectContainer.php:580 Stack trace:
#0 C:\xampp\htdocs\Fresh_Api\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Contai ner.php(331): appDevDebugProjectContainer->getAppBundle_CommandListenerService()
#1 C:\xampp\htdocs\Fresh_Api\var\cache\dev\appDevDebugProjectContainer.php(965): Symfony\Component\D ependencyInjection\Container->get('app_bundle.comm...')
#2 C:\xampp\htdocs\Fresh_Api\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php(229): appDevDebugProjectContainer->{closure}()
#3 C:\xampp\htdocs\Fresh_Api\vendor\symfony\symfony\src\Symfony\Component\EventDispatcher\EventDispatcher.php(61):Symfony\Component\EventDispatcher\EventDispatcher->sortListeners('console.command')
#4 C:\x in C:\xampp\htdocs\Fresh_Api\var\cache\dev\appDevDebugProjectContainer.php on line 580

This is of course after I try running php bin/console server:run

I have tried deleting my cache, deleting my autoload file, deleting my vendor file and reinstalling composer. I have tried to look to see if there are any dependencies that are missing. (I could have missed something here)

The file it's talking about is a generated file so something about it is not properly noticing that that class exists.

Here is the CommandListener

namespace Directive\MultiTenant\MasterBundle\EventListener;

use Directive\MultiTenant\MasterBundle\Connection\ConnectionWrapper;
use Directive\MultiTenant\MasterBundle\Entity\Tenant;
use Directive\MultiTenant\MasterBundle\Repository\TenantRepository;
use AppBundle\TenantProviderInterface;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\InputOption;

The appDevDebugProjectContainer is a little large so I'll wait to see if there are any response to see if it's even needed as I'm sure it's something else that is causing it not to generate the proper information needed.

thanks for any input you have.

EDIT: This is a link here noting it's the same issue however this exact issue there is already resolved before all this. Here is my code for that section.

 "autoload" : {
    "psr-4": {
        "AppBundle\\": "src/AppBundle"
    },
    "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
},

This was already fixed already. here is another link I used to try to solve my issue that of course had no help.

php bin/console symfony commands give a fatal error

and another

Symfony 3.3 Getting ClassNotFoundException

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongtang6775 dongtang6775 4年前

    All Credit goes to Cerad the answer is sadly duplicated however I did not notice something that was needed. the autoloader needs to know where it is pulling classes from and has to be setup with the new way the symfony does it now. Here is my example with my additional code to make it work.

    "autoload" : {
        "psr-4": {
            "AppBundle\\": "src/AppBundle",
            "BundleName\\": "src/BundleName"
        },
        "classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
    },
    
    点赞 评论 复制链接分享

相关推荐