问题描述
我有一个侦听器,在__construct中有一个名为$ttl
的参数,并以int类型提示,ttl的值以秒为单位。我从配置YAML文件中获取此值。
我使用$ttl
参数声明了该服务,似乎对我明确声明了。但是现在symfony失败了,直到我修复它为止。我什至无法清除缓存。
我看到的错误是:
无法自动装配服务RefreshedTokenListener:方法“ __construct()”的参数“ $ ttl”带有类型提示的“ int”,您应该显式配置其值
并且侦听器代码以:
开头class RefreshedTokenListener implements EventSubscriberInterface
{
private int $ttl;
public function __construct(int $ttl)
{
$this->ttl = $ttl;
}
...
并且服务声明为:
services:
_defaults:
autowire: true
autoconfigure: true
UserBundle\:
resource: '../../../'
exclude:
- '../../../Domain/Entity/'
- '../../../Infrastructure/Repository/'
- '../../../Infrastructure/DependencyInjection/'
...
app.listener.refreshedtokenlistener:
class: UserBundle\Application\Listeners\RefreshedTokenListener
arguments:
$ttl: '%gesdinet_jwt_refresh_token.ttl%'
我试图在$ttl
的{{1}}参数中强制使用固定号码
__construct()
但还是我应该明确配置其值的错误消息
我看不到出什么问题了,但是没有用。我正在使用symfony 5.1,PHP 7.4.8
我刚刚完全删除了arguments:
$ttl: 8990000
声明行,因此错误应该消失了。但是仍然存在相同的错误,因此必须在某处自动声明此服务,这就是我看到的错误。如何找到错误?我没有在dev.log上看到任何有关此的信息
解决方法
这是因为您要使用alias instead of its full classname声明服务。目前,您的服务永远不会自动接线。
您必须执行以下操作:
services:
# ...
app.listener.refreshedtokenlistener:
class: UserBundle\Application\Listeners\RefreshedTokenListener
arguments:
$ttl: '%gesdinet_jwt_refresh_token.ttl%'
UserBundle\Application\Listeners\RefreshedTokenListener: '@app.listener.refreshedtokenlistener'