Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何解决Symfony3中的ServiceNotFoundException_Php_Symfony_Jwt - Fatal编程技术网

Php 如何解决Symfony3中的ServiceNotFoundException

Php 如何解决Symfony3中的ServiceNotFoundException,php,symfony,jwt,Php,Symfony,Jwt,错误 我需要什么 我需要用symfony验证angular2应用程序 config.yml ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php The service "token_authenticator" has a dependency on a non-existent service "lexik_jwt_authentication.jwt_encoder". secu

错误

我需要什么

  • 我需要用symfony验证angular2应用程序
config.yml

 ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php 
 The service "token_authenticator" has a dependency on a non-existent service "lexik_jwt_authentication.jwt_encoder".
security.yml

lexik_jwt_authentication:
private_key_path: '%kernel.root_dir%/../var/jwt/private.pem'
public_key_path:  '%kernel.root_dir%/../var/jwt/public.pem'
pass_phrase:      '%jwt_key_pass_phrase%'
token_ttl: 3600
服务.yml

 firewalls:
    main:
        pattern: ^/
        logout:       true
        anonymous:    true
        stateless: true

        guard:
            authenticators:
                - 'token_authenticator'
路由.yml

 services:

 token_authenticator:
    class: AcmeStoreBundle\Security\TokenAuthenticator
    arguments: ['@lexik_jwt_authentication.jwt_encoder', '@doctrine_mongodb']
登录控制器代码

 acme_store_login_user:
   type: rest
   path:     /login_check
   defaults: { _controller: AcmeStoreBundle:Login:login }
name_prefix:  api_
参考文献:

  • 谁能建议我如何解决这个问题

    • 您使用的是2.x版本,其中(正如您从变更日志中看到的)lexik_jwt_身份验证.jwt_编码器服务(来自1.x版本)已不复存在。您应该使用
      lexik\u jwt\u authentication.encoder.default

      已在中删除服务lexik_jwt_authentication.jwt_编码器 支持的lexik_jwt_authentication.encoder.default OpenSSL和phpseclib加密引擎


      我在Symfony 4中遇到了同样的问题,因为我的LoginConroller扩展了BaseController,所以请确保LoginController扩展了Controller类。像这样:

       token_authenticator:
          class: Acme\StoreBundle\Security\TokenAuthenticator
          arguments: ['@lexik_jwt_authentication.encoder.default', '@doctrine_mongodb']
      

      }

      您使用的是哪个版本的LexikJWTAuthenticationBundle?正如您所看到的,我引用了上面2.0版的链接,现在我在尝试从命名空间“AcmeStoreBundle\Security”加载类“TokenAuthenticator”时遇到了新问题。您是否忘记了另一个名称空间的“use”语句?发布
      AcmeStoreBundle/Security/TokenAuthenticator.php
      文件我上载了完整的文件url您使用了错误的名称空间。另外,在你的问题中粘贴代码。你能在代码片段中建议关于实体管理器orm:mysql的内容吗?但是我需要mongo db,所以我喜欢使用DoctrineMongoDB;公共函数uu构造(JWTEncoderInterface$jwtEncoder,DoctrineMongoDB$em){$this->jwtEncoder=$jwtEncoder;$this->em=$em;}
       token_authenticator:
          class: Acme\StoreBundle\Security\TokenAuthenticator
          arguments: ['@lexik_jwt_authentication.encoder.default', '@doctrine_mongodb']
      
      class LoginController extends Controller {
        .......