doufeng1249 2017-07-25 15:39
浏览 115
已采纳

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 2017-07-25 17:10
    关注

    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" ]
    },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵