Laravel的项目如何避免Reflection Exception,产生的原因是什么?

How to avoid Reflection Exception in Laravel's project and what are the causes which produce it?

我使用 Laravel 创建了一个名为 my-school 的项目。一切正常,除非我 运行 我的项目使用 XAMPP.
然后我使用这个 url: localhost/my-school/public/

这是引发的异常:

Fatal error: Uncaught exception 'ReflectionException' with message
'Class MySchool\Http\Kernel does not exist' in
E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Container\Container.php:776
Stack trace: #0
E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Container\Container.php(776):
ReflectionClass->__construct('MySchool\Http\K...') #1
E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Container\Container.php(656):
Illuminate\Container\Container->build('MySchool\Http\K...', Array)
#2 E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(613):
Illuminate\Container\Container->make('MySchool\Http\K...', Array) #3
E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Container\Container.php(229):
Illuminate\Foundation\Application->make('MySchool\Http\K...', Array)
#4 E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Container\Container.php(773):
Illuminate\Container\Container->Illuminate\Container\{clo in
E:\xampp\htdocs\my-school\vendor\laravel\framework\src\Illuminate\Container\Container.php
on line 776

这是我的 composer.json 文件内容:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.0.*"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

有人可以帮我找出项目的问题吗?

查看 composer autoload 的值:

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\": "app/"
    }
},

这意味着 app\ folder 内所有 类 的名称空间应以 'App\' 作为名称开头。在您的情况下,错误状态为:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class MySchool\Http\Kernel does not exist'

MySchool\Http\Kernel 永远不会加载,因为它不存在。相反,您的作曲家需要以下结构:

Class App\Http\Kernel

看出区别了吗?然后,尝试重命名应用程序如下:

php artisan app:name MySchool 

这样一来,所有 类 都将按我认为的方式路由到 MySchool。