Laravel 错误“ReflectionException"-“类 AppHttpKernel 不存在"

2022-01-14 00:00:00 namespaces php laravel psr-4

我试图使用我在学校一年前开发的 laravel 项目,但遇到了一些问题.在我的托管服务服务器上上传整个项目后,我的浏览器和 SSH shell 都出现了这些错误.

I was trying to go live with a laravel project i developped a year back in school and i ran into some issue. After uploading the whole project on my hosting service's server, i got these errors on my browser as well as on my SSH shell.

致命错误:在/home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php 中出现消息Class AppHttpKernel 不存在"的未捕获异常ReflectionException":779堆栈跟踪:#0/home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('AppHttpKernel') #1/home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(659): IlluminateContainerContainer->build('AppHttpKernel', Array) #2/home/客户端/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): IlluminateContainerContainer->make('AppHttpKernel', Array) #3/home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(229): IlluminateFoundationApplication->make('AppHttpKernel', Array) #4/home/clients//home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php 中的 ffa41f94063 位于第 779 行

Fatal error: Uncaught exception 'ReflectionException' with message 'Class AppHttpKernel does not exist' in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php:779 Stack trace: #0 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(779): ReflectionClass->__construct('AppHttpKernel') #1 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(659): IlluminateContainerContainer->build('AppHttpKernel', Array) #2 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(644): IlluminateContainerContainer->make('AppHttpKernel', Array) #3 /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php(229): IlluminateFoundationApplication->make('AppHttpKernel', Array) #4 /home/clients/ffa41f94063 in /home/clients/ffa41f94063541f86a0fe6602a73caa1/myforms/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 779

我认为这可能与我的命名空间配置有关,因为我还没有完全理解.

I think it could be related to my namespace configuration, because i haven't all understood yet.

这是我的 composer.json 文件:

Here is my composer.json file :

{
	"name": "laravel/laravel",
	"description": "The Laravel Framework.",
	"keywords": ["framework", "laravel"],
	"license": "MIT",
	"type": "project",
	"require": {
		"laravel/framework": "5.0.*",
		"illuminate/html": "5.*",
		"barryvdh/laravel-dompdf": "0.5.*",
		"guzzlehttp/guzzle": "~4.0"

	},
	"require-dev": {
		"phpunit/phpunit": "~4.0",
		"phpspec/phpspec": "~2.1"
	},
	"autoload": {
		"classmap": [
			"database"
		],
		"psr-4": {
			"App\": "myforms/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"
	}
}

我已经做了什么:

  • 删除/vendor 并使用 composer install
  • 进行新安装
  • 作曲家转储自动加载
  • 作曲家更新顺便说一句,当我插入 composer update
  • 时出现错误
  • Delete /vendor and make a new install with composer install
  • composer dump-autoload
  • composer update btw, I get the error when I insert the composer update

如果我应该发布另一个可能有用的文件,请通知我.

Please inform me if i should post another file that could be useful.

提前感谢您的帮助.

推荐答案

在composer.json中修改:

In composer.json change:

 "psr-4": {
        "App\": "myforms/app/"
    } 

到:

 "psr-4": {
        "App\": "app/"
    }

在服务器上,在您的源目录中,运行 composer update 然后 composer dump-autoload

On the server, in your source directory, run composer update then composer dump-autoload

Laravel 中的 PSR-4 查找相对于项目根目录的命名空间

PSR-4 in Laravel looks for namespaces relative to the root of the project

相关文章