Symfony 3 - (文件路径) 的定义没有 class 属性并且似乎引用了全局命名空间中的 class 或接口

Symfony 3 - The definition for (file path) has no class attribute and appears to reference a class or interface in the global namespace

有没有人遇到过下面的错误并且知道问题出在哪里?我正在使用异常包为 REST API.

输出基于 JSON 的异常消息
    C:\htdocs\projects\myproject>php bin/console cache:clear --no-warmup
    PHP Fatal error:  Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition
     for "ApiExceptionBundle\Component\Factory\ResponseFactoryInterface" has no class attribute, and appears to
     reference a class or interface in the global namespace. Leaving out the "class" attribute is only allowed
    for namespaced classes. Please specify the class attribute explicitly to get rid of this error. in C:\htdoc
    s\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitio
    nValidityPass.php:52
    Stack trace:
    #0 C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\Com
    piler.php(143): Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass->process(Object(
    Symfony\Component\DependencyInjection\ContainerBuilder))
    #1 C:\htdocs\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBui
    lder.php(731): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Symfony\ in C:\htdoc
    s\projects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitio
    nValidityPass.php on line 52

    Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition for
    "ApiExceptionBundle\Component\Factory\ResponseFactoryInterface" has no class attribute, and appears to refe
    rence a class or interface in the global namespace. Leaving out the "class" attribute is only allowed for n
    amespaced classes. Please specify the class attribute explicitly to get rid of this error. in C:\htdocs\pro
    jects\myproject\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitionVali
    dityPass.php on line 52

    Symfony\Component\DependencyInjection\Exception\RuntimeException: The definition for "ApiExceptionBundle\Co
    mponent\Factory\ResponseFactoryInterface" has no class attribute, and appears to reference a class or inter
    face in the global namespace. Leaving out the "class" attribute is only allowed for namespaced classes. Ple
    ase specify the class attribute explicitly to get rid of this error. in C:\htdocs\projects\myproject\vendor\s
    ymfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\CheckDefinitionValidityPass.php on line 5
    2

    Call Stack:
        4.6333   13914032   1. Symfony\Component\Debug\ErrorHandler->handleException() C:\htdocs\projects\alire
    st\vendor\symfony\symfony\src\Symfony\Component\Debug\ErrorHandler.php:0

C:\htdocs\projects\myproject>

这是它引用的文件:

<?php

namespace ApiExceptionBundle\Component\Factory;

use ApiExceptionBundle\Component\Api\ApiProblemInterface;

interface ResponseFactoryInterface
{
    public function createResponse(ApiProblemInterface $apiProblem);
}

都是here in the doc

类型提示 (ApiExceptionBundle\Component\Api\ApiProblemInterface) 与服务 ID (ApiExceptionBundle\Component\Api\ApiProblem ?) 不匹配。这意味着参数不能自动装配。

您应该添加一个别名

services:
    ApiExceptionBundle\Component\Api\ApiProblemInterface: '@ApiExceptionBundle\Component\Api\ApiProblem'