首页 > 解决方案 > Lumen 中的 DarkaOnline 招摇集成未注册 Swagger\Lume::ServiceProvider

问题描述

我正在尝试将 swagger 集成到 mu lumen 项目中。Lumen 版本是 5.7 在我的本地系统中它工作正常,但在服务器(Ubuntu)中,由于内存问题我无法遵循命令,所以我将供应商文件夹、composer.json 和 composer.lock 文件从本地上传到服务器,我运行 composer dump-autoload 命令。

我按照这个文档进行了招摇集成。

https://github.com/DarkaOnLine/SwaggerLume

然后在我的终端中运行 php artisan swagger-lume:publish

但我得到了

在 Apllication.php 第 183 行中找不到类“SwaggerLume\ServiceProvider”

我已经配置了我的 bootstrap/app.php 文件,如下所示

未注释 $app->withFacades(); 并添加了 $app->configure('swagger-lume'); 在注册容器绑定之前。我添加了 $app->register(\SwaggerLume\ServiceProvider::class); 里面注册服务提供者。

<?php

 require_once __DIR__.'/../vendor/autoload.php';

 try {
  (new Dotenv\Dotenv(__DIR__.'/../'))->load();
 } catch (Dotenv\Exception\InvalidPathException $e) {
//
}

 /*
   |--------------------------------------------------------------------------
   | Create The Application
   |--------------------------------------------------------------------------
   |
   | Here we will load the environment and create the application instance
   | that serves as the central piece of this framework. We'll use this
   | application as an "IoC" container and router for this framework.
   |
 */

  $app = new Laravel\Lumen\Application(
  realpath(__DIR__.'/../')
  );

  $app->withFacades();

  $app->withEloquent();

  $app->configure('swagger-lume');

 /*
 |--------------------------------------------------------------------------
 | Register Container Bindings
 |--------------------------------------------------------------------------
 |
 | Now we will register a few bindings in the service container. We will
 | register the exception handler and the console kernel. You may add
 | your own bindings here if you like or you can make another file.
 |
 */

 $app->singleton(
  Illuminate\Contracts\Debug\ExceptionHandler::class,
  App\Exceptions\Handler::class
 );

 $app->singleton(
  Illuminate\Contracts\Console\Kernel::class,
  App\Console\Kernel::class
);

/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/


$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);

/*
 |--------------------------------------------------------------------------
 | Register Service Providers
 |--------------------------------------------------------------------------
 |
 | Here we will register all of the application's service providers which
 | are used to bind services into the container. Service providers are
 | totally optional, so you are not required to uncomment this line.
 |

*/

 $app->register(App\Providers\AuthServiceProvider::class);
 $app->register(\SwaggerLume\ServiceProvider::class);

标签: swaggerlumenservice-provider

解决方案


推荐阅读