我在 service.yml 文件中遇到DI问题,我的文件包含以下代码:
...
...
AppBundle\Providers\BuilderInterface:
class: AppBundle\Providers\Builder
arguments:
$service: '@Google_Service_Bigquery'
$job: '@Google_Service_Bigquery_Job'
$jobConfExtract: @Google_Service_Bigquery_JobConfigurationExtract'
$jobConf: '@Google_Service_Bigquery_JobConfiguration'
...
...
但是,Symfony 3.4告诉我这个错误:
Cannot autowire service "AppBundle\Providers\Builder": argument "$service" of method "__construct()" references class "Google_Service_Bigquery" but no such service exists. It cannot be auto-registered because it is from a different root namespace.
我在Google库中打开 composer.json :
"autoload": {
"psr-0": {
"Google_Service_": "src"
}
}
他们使用PSR-0自动加载类,但在Symfony 3中它不起作用。
我该如何解决这个问题?
答案 0 :(得分:0)
将提及的课程注册为服务:
Google_Service_Bigquery: ~
这相当于:
Google_Service_Bigquery:
class: Google_Service_Bigquery
然后您可以从参数列表中删除该行,因为它将自动连接:
$service: '@Google_Service_Bigquery'