【问题标题】:Symfony - ClassNotFoundException in AppKernel.phpSymfony - AppKernel.php 中的 ClassNotFoundException
【发布时间】:2015-10-11 13:04:07
【问题描述】:

在将我的应用程序投入生产时,我不得不通过 FTP 传输 JMS 序列化程序,因为我无法在生产服务器上使用 composer。

成功了,我在供应商那里看到了。

我的 AppKernel 与本地相同(在生产环境和开发环境中都经过测试):

<?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 Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
        new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
        new Hager\TransformationBundle\TransformationBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle()
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $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');
}
}

但我收到了一个非常奇怪的消息

AppKernel.php 第 22 行中的 ClassNotFoundException: 尝试从命名空间“JMS\SerializerBundle”加载类“JMSSerializerBundle”。 您是否忘记了另一个命名空间的“使用”语句?

由于控制台在生产服务器上也不可用,我做了rm -RF /app/cache/*,但仍然出现错误。

帮助很受欢迎。

【问题讨论】:

  • 看起来类加载器没有加载 JMSSerializer 类。您是否在生产中更新了 composer.json 和 composer.lock 文件,或者您只是将 jms 序列化程序上传到供应商文件夹?
  • 他说他不能在生产服务器中使用composer
  • 我不能在生产中使用作曲家,所以是的,我只是在供应商文件夹中通过 ftp 上传它。

标签: php symfony


【解决方案1】:

同时再次上传vendor/composer目录。

并上传您的web 目录,因为可能会有新资产。

然后去app/cache删除里面的所有东西。

另一种方法:

下载并安装CoreSphere ConsoleBundle

在 app_dev.php 中添加你的 ip 地址:

if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1', '100.200.300.400')) || php_sapi_name() === 'cli-server')
)

(将 100.200.300.400 替换为您自己的 ip)并将此文件上传到服务器。然后在 app_dev.php/_console 中访问您的网站,您可以从那里执行控制台命令。

【讨论】:

    【解决方案2】:

    你说你不能在你的产品服务器上运行 Composer(为什么?!)。在这种情况下,即使您将 JMS 序列化程序文件复制到供应商目录,它们也不会被 composer 生成的自动加载器自动加载。您需要在 vendor/composer 目录中编辑 autoload_namespaces.php 文件并添加以下行:

    'JMS\\SerializerBundle' => array ($vendorDir . '/jms/serializer-bundle'),
    

    【讨论】:

      【解决方案3】:

      请勿重命名或替换 Comoser.lock 和composer.json 文件。 安装新项目symfony new project 并将文件夹从损坏的项目替换为新项目:app、src、web。

      【讨论】:

        猜你喜欢
        • 2016-09-06
        • 2018-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-29
        • 1970-01-01
        • 1970-01-01
        • 2021-06-08
        相关资源
        最近更新 更多